﻿	function checkboxchange(){}
	function headcheckboxchange(){}
;
(function ($) {
	$.jgrid = {
		defaults : {
			recordtext : "共 {2} 条",
			emptyrecords : "共 0 条",
			loadtext : "读取中...",
			pgtext : "page {0} of {1}"
		},
		search : {
			caption : "搜索...",
			Find : "查找",
			Reset : "重置",
			odata : ['等于&nbsp;&nbsp;', '不等&nbsp;&nbsp;', '小于&nbsp;&nbsp;', '小于等于', '大于&nbsp;&nbsp;', '大于等于', '开始于', '不开始于', '属于&nbsp;&nbsp;', '不属于', '结束于', '不结束于', '包含&nbsp;&nbsp;', '不包含'],
			groupOps : [{
					op : "AND",
					text : "所有"
				}, {
					op : "OR",
					text : "任一"
				}
			],
			matchText : " 匹配",
			rulesText : " 规则"
		},
		edit : {
			addCaption : "添加记录",
			editCaption : "编辑记录",
			bSubmit : "提交",
			bCancel : "取消",
			bClose : "关闭",
			saveData : "数据已改变，是否保存？",
			bYes : "是",
			bNo : "否",
			bExit : "取消",
			msg : {
				required : "此字段必需",
				number : "请输入有效数字",
				minValue : "输值必须大于等于 ",
				maxValue : "输值必须小于等于 ",
				email : "这不是有效的e-mail地址",
				integer : "请输入有效整数",
				date : "请输入有效时间",
				url : "无效网址。前缀必须为 ('http://' 或 'https://')",
				nodefined : " 未定义！",
				novalue : " 需要返回值！",
				customarray : "自定义函数需要返回数组！",
				customfcheck : "Custom function should be present in case of custom checking!"
			}
		},
		view : {
			caption : "查看记录",
			bClose : "关闭"
		},
		del : {
			caption : "删除",
			msg : "删除所选记录？",
			bSubmit : "删除",
			bCancel : "取消"
		},
		nav : {
			edittext : "",
			edittitle : "编辑所选记录",
			addtext : "",
			addtitle : "添加新记录",
			deltext : "",
			deltitle : "删除所选记录",
			searchtext : "",
			searchtitle : "查找",
			refreshtext : "",
			refreshtitle : "刷新表格",
			alertcap : "注意",
			alerttext : "请选择记录",
			viewtext : "",
			viewtitle : "查看所选记录"
		},
		col : {
			caption : "选择列",
			bSubmit : "确定",
			bCancel : "取消"
		},
		errors : {
			errcap : "错误",
			nourl : "没有设置url",
			norecords : "没有要处理的记录",
			model : "colNames 和 colModel 长度不等！"
		},
		formatter : {
			integer : {
				thousandsSeparator : " ",
				defaultValue : '0'
			},
			number : {
				decimalSeparator : ".",
				thousandsSeparator : " ",
				decimalPlaces : 2,
				defaultValue : '0.00'
			},
			currency : {
				decimalSeparator : ".",
				thousandsSeparator : " ",
				decimalPlaces : 2,
				prefix : "",
				suffix : "",
				defaultValue : '0.00'
			},
			date : {
				dayNames : ["Sun", "Mon", "Tue", "Wed", "Thr", "Fri", "Sat", "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"],
				monthNames : ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec", "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"],
				AmPm : ["am", "pm", "AM", "PM"],
				S : function (j) {
					return j < 11 || j > 13 ? ['st', 'nd', 'rd', 'th'][Math.min((j - 1) % 10, 3)] : 'th'
				},
				srcformat : 'Y-m-d',
				newformat : 'm-d-Y',
				masks : {
					ISO8601Long : "Y-m-d H:i:s",
					ISO8601Short : "Y-m-d",
					ShortDate : "Y/j/n",
					LongDate : "l, F d, Y",
					FullDateTime : "l, F d, Y g:i:s A",
					MonthDay : "F d",
					ShortTime : "g:i A",
					LongTime : "g:i:s A",
					SortableDateTime : "Y-m-d\\TH:i:s",
					UniversalSortableDateTime : "Y-m-d H:i:sO",
					YearMonth : "F, Y"
				},
				reformatAfterEdit : false
			},
			baseLinkUrl : '',
			showAction : '',
			target : '',
			checkbox : {
				disabled : true
			},
			idName : 'id'
		}
	};
})(jQuery);
var totalnumcnzz; ;
(function ($) {
	$.jgrid = $.jgrid || {};
	$.extend($.jgrid, {
		htmlDecode : function (value) {
			if (value == '&nbsp;' || value == '&#160;' || (value.length == 1 && value.charCodeAt(0) == 160)) {
				return "";
			}
			return !value ? value : String(value).replace(/&amp;/g, "&").replace(/&gt;/g, ">").replace(/&lt;/g, "<").replace(/&quot;/g, '"');
		},
		htmlEncode : function (value) {
			return !value ? value : String(value).replace(/&/g, "&amp;").replace(/>/g, "&gt;").replace(/</g, "&lt;").replace(/\"/g, "&quot;");
		},
		format : function (format) {
			var args = $.makeArray(arguments).slice(1);
			if (format === undefined) {
				format = "";
			}
			return format.replace(/\{(\d+)\}/g, function (m, i) {
				return args[i];
			});
		},
		getCellIndex : function (cell) {
			var c = $(cell);
			if (c.is('tr')) {
				return -1;
			}
			c = (!c.is('td') && !c.is('th') ? c.closest("td,th") : c)[0];
			if ($.browser.msie) {
				return $.inArray(c, c.parentNode.cells);
			}
			return c.cellIndex;
		},
		stripHtml : function (v) {
			v = v + "";
			var regexp = /<("[^"]*"|'[^']*'|[^'">])*>/gi;
			if (v) {
				v = v.replace(regexp, "");
				return (v && v !== '&nbsp;' && v !== '&#160;') ? v.replace(/\"/g, "'") : "";
			} else {
				return v;
			}
		},
		stringToDoc : function (xmlString) {
			var xmlDoc;
			if (typeof xmlString !== 'string') {
				return xmlString;
			}
			try {
				var parser = new DOMParser();
				xmlDoc = parser.parseFromString(xmlString, "text/xml");
			} catch (e) {
				xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
				xmlDoc.async = false;
				xmlDoc.loadXML(xmlString);
			}
			return (xmlDoc && xmlDoc.documentElement && xmlDoc.documentElement.tagName != 'parsererror') ? xmlDoc : null;
		},
		parse : function (jsonString) {
			var js = jsonString;
			if (js.substr(0, 9) == "while(1);") {
				js = js.substr(9);
			}
			if (js.substr(0, 2) == "/*") {
				js = js.substr(2, js.length - 4);
			}
			if (!js) {
				js = "{}";
			}
			return ($.jgrid.useJSON === true && typeof(JSON) === 'object' && typeof(JSON.parse) === 'function') ? JSON.parse(js) : eval('(' + js + ')');
		},
		parseDate : function (format, date) {
			var tsp = {
				m : 1,
				d : 1,
				y : 1970,
				h : 0,
				i : 0,
				s : 0
			},
			k,
			hl,
			dM;
			if (date && date !== null && date !== undefined) {
				date = $.trim(date);
				date = date.split(/[\\\/:_;.\t\T\s-]/);
				format = format.split(/[\\\/:_;.\t\T\s-]/);
				var dfmt = $.jgrid.formatter.date.monthNames;
				var afmt = $.jgrid.formatter.date.AmPm;
				var h12to24 = function (ampm, h) {
					if (ampm === 0) {
						if (h == 12) {
							h = 0;
						}
					} else {
						if (h != 12) {
							h += 12;
						}
					}
					return h;
				};
				for (k = 0, hl = format.length; k < hl; k++) {
					if (format[k] == 'M') {
						dM = $.inArray(date[k], dfmt);
						if (dM !== -1 && dM < 12) {
							date[k] = dM + 1;
						}
					}
					if (format[k] == 'F') {
						dM = $.inArray(date[k], dfmt);
						if (dM !== -1 && dM > 11) {
							date[k] = dM + 1 - 12;
						}
					}
					if (format[k] == 'a') {
						dM = $.inArray(date[k], afmt);
						if (dM !== -1 && dM < 2 && date[k] == afmt[dM]) {
							date[k] = dM;
							tsp.h = h12to24(date[k], tsp.h);
						}
					}
					if (format[k] == 'A') {
						dM = $.inArray(date[k], afmt);
						if (dM !== -1 && dM > 1 && date[k] == afmt[dM]) {
							date[k] = dM - 2;
							tsp.h = h12to24(date[k], tsp.h);
						}
					}
					if (date[k] !== undefined) {
						tsp[format[k].toLowerCase()] = parseInt(date[k], 10);
					}
				}
				tsp.m = parseInt(tsp.m, 10) - 1;
				var ty = tsp.y;
				if (ty >= 70 && ty <= 99) {
					tsp.y = 1900 + tsp.y;
				} else if (ty >= 0 && ty <= 69) {
					tsp.y = 2000 + tsp.y;
				}
			}
			return new Date(tsp.y, tsp.m, tsp.d, tsp.h, tsp.i, tsp.s, 0);
		},
		jqID : function (sid) {
			sid = sid + "";
			return sid.replace(/([\.\:\[\]])/g, "\\$1");
		},
		getAccessor : function (obj, expr) {
			var ret,
			p,
			prm,
			i;
			if (typeof expr === 'function') {
				return expr(obj);
			}
			ret = obj[expr];
			if (ret === undefined) {
				try {
					if (typeof expr === 'string') {
						prm = expr.split('.');
					}
					i = prm.length;
					if (i) {
						ret = obj;
						while (ret && i--) {
							p = prm.shift();
							ret = ret[p];
						}
					}
				} catch (e) {}
				
			}
			return ret;
		},
		ajaxOptions : {},
		from : function (source, initalQuery) {
			var queryObject = function (d, q) {
				if (typeof(d) == "string") {
					d = $.data(d);
				}
				var self = this,
				_data = d,
				_usecase = true,
				_trim = false,
				_query = q,
				_stripNum = /[\$,%]/g,
				_lastCommand = null,
				_lastField = null,
				_negate = false,
				_queuedOperator = "",
				_sorting = [],
				_useProperties = true;
				if (typeof(d) == "object" && d.push) {
					if (d.length > 0) {
						if (typeof(d[0]) != "object") {
							_useProperties = false;
						} else {
							_useProperties = true;
						}
					}
				} else {
					throw "data provides is not an array";
				}
				this._hasData = function () {
					return _data === null ? false : _data.length === 0 ? false : true;
				};
				this._getStr = function (s) {
					var phrase = [];
					if (_trim) {
						phrase.push("jQuery.trim(");
					}
					phrase.push("String(" + s + ")");
					if (_trim) {
						phrase.push(")");
					}
					if (!_usecase) {
						phrase.push(".toLowerCase()");
					}
					return phrase.join("");
				};
				this._strComp = function (val) {
					if (typeof(val) == "string") {
						return ".toString()";
					} else {
						return "";
					}
				};
				this._group = function (f, u) {
					return ({
						field : f.toString(),
						unique : u,
						items : []
					});
				};
				this._toStr = function (phrase) {
					if (_trim) {
						phrase = $.trim(phrase);
					}
					if (!_usecase) {
						phrase = phrase.toLowerCase();
					}
					phrase = phrase.toString().replace(new RegExp('\\"', "g"), '\\"');
					return phrase;
				};
				this._funcLoop = function (func) {
					var results = [];
					$.each(_data, function (i, v) {
						results.push(func(v));
					});
					return results;
				};
				this._append = function (s) {
					if (_query === null) {
						_query = "";
					} else {
						_query += _queuedOperator === "" ? " && " : _queuedOperator;
					}
					if (_negate) {
						_query += "!";
					}
					_query += "(" + s + ")";
					_negate = false;
					_queuedOperator = "";
				};
				this._setCommand = function (f, c) {
					_lastCommand = f;
					_lastField = c;
				};
				this._resetNegate = function () {
					_negate = false;
				};
				this._repeatCommand = function (f, v) {
					if (_lastCommand === null) {
						return self;
					}
					if (f != null && v != null) {
						return _lastCommand(f, v);
					}
					if (_lastField === null) {
						return _lastCommand(f);
					}
					if (!_useProperties) {
						return _lastCommand(f);
					}
					return _lastCommand(_lastField, f);
				};
				this._equals = function (a, b) {
					return (self._compare(a, b, 1) === 0);
				};
				this._compare = function (a, b, d) {
					if (d === undefined) {
						d = 1;
					}
					if (a === undefined) {
						a = null;
					}
					if (b === undefined) {
						b = null;
					}
					if (a === null && b === null) {
						return 0;
					}
					if (a === null && b !== null) {
						return 1;
					}
					if (a !== null && b === null) {
						return -1;
					}
					if (!_usecase && typeof(a) !== "number" && typeof(b) !== "number") {
						a = String(a).toLowerCase();
						b = String(b).toLowerCase();
					}
					if (a < b) {
						return -d;
					}
					if (a > b) {
						return d;
					}
					return 0;
				};
				this._performSort = function () {
					if (_sorting.length === 0) {
						return;
					}
					_data = self._doSort(_data, 0);
				};
				this._doSort = function (d, q) {
					var by = _sorting[q].by,
					dir = _sorting[q].dir,
					type = _sorting[q].type,
					dfmt = _sorting[q].datefmt;
					if (q == _sorting.length - 1) {
						return self._getOrder(d, by, dir, type, dfmt);
					}
					q++;
					var values = self._getGroup(d, by, dir, type, dfmt);
					var results = [];
					for (var i = 0; i < values.length; i++) {
						var sorted = self._doSort(values[i].items, q);
						for (var j = 0; j < sorted.length; j++) {
							results.push(sorted[j]);
						}
					}
					return results;
				};
				this._getOrder = function (data, by, dir, type, dfmt) {
					var sortData = [],
					_sortData = [],
					newDir = dir == "a" ? 1 : -1,
					i,
					ab,
					j,
					findSortKey;
					if (type === undefined) {
						type = "text";
					}
					if (type == 'float' || type == 'number' || type == 'currency' || type == 'numeric') {
						findSortKey = function ($cell, a) {
							var key = parseFloat(String($cell).replace(_stripNum, ''));
							return isNaN(key) ? 0.00 : key;
						};
					} else if (type == 'int' || type == 'integer') {
						findSortKey = function ($cell, a) {
							return $cell ? parseFloat(String($cell).replace(_stripNum, '')) : 0;
						};
					} else if (type == 'date' || type == 'datetime') {
						findSortKey = function ($cell, a) {
							return $.jgrid.parseDate(dfmt, $cell).getTime();
						};
					} else if ($.isFunction(type)) {
						findSortKey = type;
					} else {
						findSortKey = function ($cell, a) {
							if (!$cell) {
								$cell = "";
							}
							return $.trim(String($cell).toUpperCase());
						};
					}
					$.each(data, function (i, v) {
						ab = by !== "" ? $.jgrid.getAccessor(v, by) : v;
						if (ab === undefined) {
							ab = "";
						}
						ab = findSortKey(ab, v);
						_sortData.push({
							'vSort' : ab,
							'index' : i
						});
					});
					_sortData.sort(function (a, b) {
						a = a.vSort;
						b = b.vSort;
						return self._compare(a, b, newDir);
					});
					j = 0;
					var nrec = data.length;
					while (j < nrec) {
						i = _sortData[j].index;
						sortData.push(data[i]);
						j++;
					}
					return sortData;
				};
				this._getGroup = function (data, by, dir, type, dfmt) {
					var results = [],
					group = null,
					last = null,
					val;
					$.each(self._getOrder(data, by, dir, type, dfmt), function (i, v) {
						val = $.jgrid.getAccessor(v, by);
						if (val === undefined) {
							val = "";
						}
						if (!self._equals(last, val)) {
							last = val;
							if (group != null) {
								results.push(group);
							}
							group = self._group(by, val);
						}
						group.items.push(v);
					});
					if (group != null) {
						results.push(group);
					}
					return results;
				};
				this.ignoreCase = function () {
					_usecase = false;
					return self;
				};
				this.useCase = function () {
					_usecase = true;
					return self;
				};
				this.trim = function () {
					_trim = true;
					return self;
				};
				this.noTrim = function () {
					_trim = false;
					return self;
				};
				this.combine = function (f) {
					var q = $.from(_data);
					if (!_usecase) {
						q.ignoreCase();
					}
					if (_trim) {
						q.trim();
					}
					var result = f(q).showQuery();
					self._append(result);
					return self;
				};
				this.execute = function () {
					var match = _query,
					results = [];
					if (match === null) {
						return self;
					}
					$.each(_data, function () {
						if (eval(match)) {
							results.push(this);
						}
					});
					_data = results;
					return self;
				};
				this.data = function () {
					return _data;
				};
				this.select = function (f) {
					self._performSort();
					if (!self._hasData()) {
						return [];
					}
					self.execute();
					if ($.isFunction(f)) {
						var results = [];
						$.each(_data, function (i, v) {
							results.push(f(v));
						});
						return results;
					}
					return _data;
				};
				this.hasMatch = function (f) {
					if (!self._hasData()) {
						return false;
					}
					self.execute();
					return _data.length > 0;
				};
				this.showQuery = function (cmd) {
					var queryString = _query;
					if (queryString === null) {
						queryString = "no query found";
					}
					if ($.isFunction(cmd)) {
						cmd(queryString);
						return self;
					}
					return queryString;
				};
				this.andNot = function (f, v, x) {
					_negate = !_negate;
					return self.and(f, v, x);
				};
				this.orNot = function (f, v, x) {
					_negate = !_negate;
					return self.or(f, v, x);
				};
				this.not = function (f, v, x) {
					return self.andNot(f, v, x);
				};
				this.and = function (f, v, x) {
					_queuedOperator = " && ";
					if (f === undefined) {
						return self;
					}
					return self._repeatCommand(f, v, x);
				};
				this.or = function (f, v, x) {
					_queuedOperator = " || ";
					if (f === undefined) {
						return self;
					}
					return self._repeatCommand(f, v, x);
				};
				this.isNot = function (f) {
					_negate = !_negate;
					return self.is(f);
				};
				this.is = function (f) {
					self._append('this.' + f);
					self._resetNegate();
					return self;
				};
				this._compareValues = function (func, f, v, how, t) {
					var fld;
					if (_useProperties) {
						fld = 'this.' + f;
					} else {
						fld = 'this';
					}
					if (v === undefined) {
						v = null;
					}
					var val = v === null ? f : v,
					swst = t.stype === undefined ? "text" : t.stype;
					switch (swst) {
					case 'int':
					case 'integer':
						val = isNaN(Number(val)) ? '0' : val;
						fld = 'parseInt(' + fld + ',10)';
						val = 'parseInt(' + val + ',10)';
						break;
					case 'float':
					case 'number':
					case 'numeric':
						val = String(val).replace(_stripNum, '');
						val = isNaN(Number(val)) ? '0' : val;
						fld = 'parseFloat(' + fld + ')';
						val = 'parseFloat(' + val + ')';
						break;
					case 'date':
					case 'datetime':
						val = String($.jgrid.parseDate(t.newfmt || 'Y-m-d', val).getTime());
						fld = 'jQuery.jgrid.parseDate("' + t.srcfmt + '",' + fld + ').getTime()';
						break;
					default:
						fld = self._getStr(fld);
						val = self._getStr('"' + self._toStr(val) + '"');
					}
					self._append(fld + ' ' + how + ' ' + val);
					self._setCommand(func, f);
					self._resetNegate();
					return self;
				};
				this.equals = function (f, v, t) {
					return self._compareValues(self.equals, f, v, "==", t);
				};
				this.greater = function (f, v, t) {
					return self._compareValues(self.greater, f, v, ">", t);
				};
				this.less = function (f, v, t) {
					return self._compareValues(self.less, f, v, "<", t);
				};
				this.greaterOrEquals = function (f, v, t) {
					return self._compareValues(self.greaterOrEquals, f, v, ">=", t);
				};
				this.lessOrEquals = function (f, v, t) {
					return self._compareValues(self.lessOrEquals, f, v, "<=", t);
				};
				this.startsWith = function (f, v) {
					var val = (v === undefined || v === null) ? f : v,
					length = _trim ? $.trim(val.toString()).length : val.toString().length;
					if (_useProperties) {
						self._append(self._getStr('this.' + f) + '.substr(0,' + length + ') == ' + self._getStr('"' + self._toStr(v) + '"'));
					} else {
						length = _trim ? $.trim(v.toString()).length : v.toString().length;
						self._append(self._getStr('this') + '.substr(0,' + length + ') == ' + self._getStr('"' + self._toStr(f) + '"'));
					}
					self._setCommand(self.startsWith, f);
					self._resetNegate();
					return self;
				};
				this.endsWith = function (f, v) {
					var val = (v === undefined || v === null) ? f : v,
					length = _trim ? $.trim(val.toString()).length : val.toString().length;
					if (_useProperties) {
						self._append(self._getStr('this.' + f) + '.substr(' + self._getStr('this.' + f) + '.length-' + length + ',' + length + ') == "' + self._toStr(v) + '"');
					} else {
						self._append(self._getStr('this') + '.substr(' + self._getStr('this') + '.length-"' + self._toStr(f) + '".length,"' + self._toStr(f) + '".length) == "' + self._toStr(f) + '"');
					}
					self._setCommand(self.endsWith, f);
					self._resetNegate();
					return self;
				};
				this.contains = function (f, v) {
					if (_useProperties) {
						self._append(self._getStr('this.' + f) + '.indexOf("' + self._toStr(v) + '",0) > -1');
					} else {
						self._append(self._getStr('this') + '.indexOf("' + self._toStr(f) + '",0) > -1');
					}
					self._setCommand(self.contains, f);
					self._resetNegate();
					return self;
				};
				this.groupBy = function (by, dir, type, datefmt) {
					if (!self._hasData()) {
						return null;
					}
					return self._getGroup(_data, by, dir, type, datefmt);
				};
				this.orderBy = function (by, dir, stype, dfmt) {
					dir = dir === undefined || dir === null ? "a" : $.trim(dir.toString().toLowerCase());
					if (stype === null || stype === undefined) {
						stype = "text";
					}
					if (dfmt === null || dfmt === undefined) {
						dfmt = "Y-m-d";
					}
					if (dir == "desc" || dir == "descending") {
						dir = "d";
					}
					if (dir == "asc" || dir == "ascending") {
						dir = "a";
					}
					_sorting.push({
						by : by,
						dir : dir,
						type : stype,
						datefmt : dfmt
					});
					return self;
				};
				return self;
			};
			return new queryObject(source, null);
		},
		extend : function (methods) {
			$.extend($.fn.jqGrid, methods);
			if (!this.no_legacy_api) {
				$.fn.extend(methods);
			}
		}
	});
	$.fn.jqGrid = function (pin) {
		if (typeof pin == 'string') {
			var fn = $.jgrid.getAccessor($.fn.jqGrid, pin);
			if (!fn) {
				throw("jqGrid - No such method: " + pin);
			}
			var args = $.makeArray(arguments).slice(1);
			return fn.apply(this, args);
		}
		return this.each(function () {
			if (this.grid) {
				return;
			}
			var p = $.extend(true, {
					url : "",
					height : 150,
					page : 1,
					rowNum : 20,
					rowTotal : null,
					records : 0,
					pager : "",
					pgbuttons : true,
					pginput : true,
					colModel : [],
					rowList : [],
					colNames : [],
					sortorder : "asc",
					sortname : "",
					datatype : "xml",
					mtype : "GET",
					altRows : false,
					selarrrow : [],
					savedRow : [],
					shrinkToFit : true,
					xmlReader : {},
					jsonReader : {},
					subGrid : false,
					subGridModel : [],
					reccount : 0,
					lastpage : 0,
					lastsort : 0,
					selrow : null,
					beforeSelectRow : null,
					onSelectRow : null,
					onSortCol : null,
					ondblClickRow : null,
					onRightClickRow : null,
					onPaging : null,
					onSelectAll : null,
					loadComplete : null,
					gridComplete : null,
					loadError : null,
					loadBeforeSend : null,
					afterInsertRow : null,
					beforeRequest : null,
					onHeaderClick : null,
					viewrecords : false,
					loadonce : false,
					multiselect : false,
					multikey : false,
					editurl : null,
					search : false,
					caption : "",
					hidegrid : true,
					hiddengrid : false,
					postData : {},
					userData : {},
					treeGrid : false,
					treeGridModel : 'nested',
					treeReader : {},
					treeANode : -1,
					ExpandColumn : null,
					tree_root_level : 0,
					prmNames : {
						page : "page",
						rows : "rows",
						sort : "sidx",
						order : "sord",
						search : "_search",
						nd : "nd",
						id : "id",
						oper : "oper",
						editoper : "edit",
						addoper : "add",
						deloper : "del",
						subgridid : "id",
						npage : null,
						totalrows : "totalrows"
					},
					forceFit : false,
					gridstate : "visible",
					cellEdit : false,
					cellsubmit : "remote",
					nv : 0,
					loadui : "enable",
					toolbar : [false, ""],
					scroll : false,
					multiboxonly : false,
					deselectAfterSort : true,
					scrollrows : false,
					autowidth : false,
					scrollOffset : 18,
					cellLayout : 5,
					subGridWidth : 20,
					multiselectWidth : 20,
					gridview : false,
					rownumWidth : 25,
					rownumbers : false,
					pagerpos : 'center',
					recordpos : 'right',
					footerrow : false,
					userDataOnFooter : false,
					hoverrows : true,
					altclass : 'ui-priority-secondary',
					viewsortcols : [false, 'vertical', true],
					resizeclass : '',
					autoencode : false,
					remapColumns : [],
					ajaxGridOptions : {},
					direction : "ltr",
					toppager : false,
					headertitles : false,
					scrollTimeout : 40,
					data : [],
					_index : {},
					grouping : false,
					groupingView : {
						groupField : [],
						groupOrder : [],
						groupText : [],
						groupColumnShow : [],
						groupSummary : [],
						showSummaryOnHide : false,
						sortitems : [],
						sortnames : [],
						groupDataSorted : false,
						summary : [],
						summaryval : [],
						plusicon : 'ui-icon-circlesmall-plus',
						minusicon : 'ui-icon-circlesmall-minus'
					},
					ignoreCase : false
				}, $.jgrid.defaults, pin || {});
			var grid = {
				headers : [],
				cols : [],
				footers : [],
				dragStart : function (i, x, y) {
					this.resizing = {
						idx : i,
						startX : x.clientX,
						sOL : y[0]
					};
					this.hDiv.style.cursor = "col-resize";
					this.curGbox = $("#rs_m" + p.id, "#gbox_" + p.id);
					this.curGbox.css({
						display : "block",
						left : y[0],
						top : y[1],
						height : y[2]
					});
					if ($.isFunction(p.resizeStart)) {
						p.resizeStart.call(this, x, i);
					}
					document.onselectstart = function () {
						return false;
					};
				},
				dragMove : function (x) {
					if (this.resizing) {
						var diff = x.clientX - this.resizing.startX,
						h = this.headers[this.resizing.idx],
						newWidth = p.direction === "ltr" ? h.width + diff : h.width - diff,
						hn,
						nWn;
						if (newWidth > 33) {
							this.curGbox.css({
								left : this.resizing.sOL + diff
							});
							if (p.forceFit === true) {
								hn = this.headers[this.resizing.idx + p.nv];
								nWn = p.direction === "ltr" ? hn.width - diff : hn.width + diff;
								if (nWn > 33) {
									h.newWidth = newWidth;
									hn.newWidth = nWn;
								}
							} else {
								this.newWidth = p.direction === "ltr" ? p.tblwidth + diff : p.tblwidth - diff;
								h.newWidth = newWidth;
							}
						}
					}
				},
				dragEnd : function () {
					this.hDiv.style.cursor = "default";
					if (this.resizing) {
						var idx = this.resizing.idx,
						nw = this.headers[idx].newWidth || this.headers[idx].width;
						nw = parseInt(nw, 10);
						this.resizing = false;
						$("#rs_m" + p.id).css("display", "none");
						p.colModel[idx].width = nw;
						this.headers[idx].width = nw;
						this.headers[idx].el.style.width = nw + "px";
						this.cols[idx].style.width = nw + "px";
						if (this.footers.length > 0) {
							this.footers[idx].style.width = nw + "px";
						}
						if (p.forceFit === true) {
							nw = this.headers[idx + p.nv].newWidth || this.headers[idx + p.nv].width;
							this.headers[idx + p.nv].width = nw;
							this.headers[idx + p.nv].el.style.width = nw + "px";
							this.cols[idx + p.nv].style.width = nw + "px";
							if (this.footers.length > 0) {
								this.footers[idx + p.nv].style.width = nw + "px";
							}
							p.colModel[idx + p.nv].width = nw;
						} else {
							p.tblwidth = this.newWidth || p.tblwidth;
							$('table:first', this.bDiv).css("width", p.tblwidth + "px");
							$('table:first', this.hDiv).css("width", p.tblwidth + "px");
							this.hDiv.scrollLeft = this.bDiv.scrollLeft;
							if (p.footerrow) {
								$('table:first', this.sDiv).css("width", p.tblwidth + "px");
								this.sDiv.scrollLeft = this.bDiv.scrollLeft;
							}
						}
						if ($.isFunction(p.resizeStop)) {
							p.resizeStop.call(this, nw, idx);
						}
					}
					this.curGbox = null;
					document.onselectstart = function () {
						return true;
					};
				},
				populateVisible : function () {
					if (grid.timer) {
						clearTimeout(grid.timer);
					}
					grid.timer = null;
					var dh = $(grid.bDiv).height();
					if (!dh) {
						return;
					}
					var table = $("table:first", grid.bDiv);
					var rows = $("> tbody > tr:gt(0):visible:first", table);
					var rh = rows.outerHeight() || grid.prevRowHeight;
					if (!rh) {
						return;
					}
					grid.prevRowHeight = rh;
					var rn = p.rowNum;
					var scrollTop = grid.scrollTop = grid.bDiv.scrollTop;
					var ttop = Math.round(table.position().top) - scrollTop;
					var tbot = ttop + table.height();
					var div = rh * rn;
					var page,
					npage,
					empty;
					if (tbot < dh && ttop <= 0 && (p.lastpage === undefined || parseInt((tbot + scrollTop + div - 1) / div, 10) <= p.lastpage)) {
						npage = parseInt((dh - tbot + div - 1) / div, 10);
						if (tbot >= 0 || npage < 2 || p.scroll === true) {
							page = Math.round((tbot + scrollTop) / div) + 1;
							ttop = -1;
						} else {
							ttop = 1;
						}
					}
					if (ttop > 0) {
						page = parseInt(scrollTop / div, 10) + 1;
						npage = parseInt((scrollTop + dh) / div, 10) + 2 - page;
						empty = true;
					}
					if (npage) {
						if (p.lastpage && page > p.lastpage || p.lastpage == 1) {
							return;
						}
						if (grid.hDiv.loading) {
							grid.timer = setTimeout(grid.populateVisible, p.scrollTimeout);
						} else {
							p.page = page;
							if (empty) {
								grid.selectionPreserver(table[0]);
								grid.emptyRows(grid.bDiv, false);
							}
							grid.populate(npage);
						}
					}
				},
				scrollGrid : function () {
					if (p.scroll) {
						var scrollTop = grid.bDiv.scrollTop;
						if (grid.scrollTop === undefined) {
							grid.scrollTop = 0;
						}
						if (scrollTop != grid.scrollTop) {
							grid.scrollTop = scrollTop;
							if (grid.timer) {
								clearTimeout(grid.timer);
							}
							grid.timer = setTimeout(grid.populateVisible, p.scrollTimeout);
						}
					}
					grid.hDiv.scrollLeft = grid.bDiv.scrollLeft;
					if (p.footerrow) {
						grid.sDiv.scrollLeft = grid.bDiv.scrollLeft;
					}
				},
				selectionPreserver : function (ts) {
					var p = ts.p;
					var sr = p.selrow,
					sra = p.selarrrow ? $.makeArray(p.selarrrow) : null;
					var left = ts.grid.bDiv.scrollLeft;
					var complete = p.gridComplete;
					p.gridComplete = function () {
						p.selrow = null;
						p.selarrrow = [];
						if (p.multiselect && sra && sra.length > 0) {
							for (var i = 0; i < sra.length; i++) {
								if (sra[i] != sr) {
									$(ts).jqGrid("setSelection", sra[i], false);
								}
							}
						}
						if (sr) {
							$(ts).jqGrid("setSelection", sr, false);
						}
						ts.grid.bDiv.scrollLeft = left;
						p.gridComplete = complete;
						if (p.gridComplete) {
							complete();
						}
					};
				}
			};
			if (this.tagName != 'TABLE') {
				alert("Element is not a table");
				return;
			}
			$(this).empty();
			this.p = p;
			var i,
			dir,
			ts;
			if (this.p.colNames.length === 0) {
				for (i = 0; i < this.p.colModel.length; i++) {
					this.p.colNames[i] = this.p.colModel[i].label || this.p.colModel[i].name;
				}
			}
			if (this.p.colNames.length !== this.p.colModel.length) {
				alert($.jgrid.errors.model);
				return;
			}
			var gv = $("<div class='ui-jqgrid-view'></div>"),
			ii,
			isMSIE = $.browser.msie ? true : false,
			isSafari = false;
			ts = this;
			ts.p.direction = $.trim(ts.p.direction.toLowerCase());
			if ($.inArray(ts.p.direction, ["ltr", "rtl"]) == -1) {
				ts.p.direction = "ltr";
			}
			dir = ts.p.direction;
			$(gv).insertBefore(this);
			$(this).appendTo(gv).removeClass("scroll");
			var eg = $("<div class='ui-jqgrid ui-widget ui-widget-content ui-corner-all'></div>");
			$(eg).insertBefore(gv).attr({
				"id" : "gbox_" + this.id,
				"dir" : dir
			});
			$(gv).appendTo(eg).attr("id", "gview_" + this.id);
			if (isMSIE && $.browser.version <= 6) {
				ii = '<iframe style="display:block;position:absolute;z-index:-1;filter:Alpha(Opacity=\'0\');" src="javascript:false;"></iframe>';
			} else {
				ii = "";
			}
			$("<div class='ui-widget-overlay jqgrid-overlay' id='lui_" + this.id + "'></div>").append(ii).insertBefore(gv);
			$("<div class='loading ui-state-default ui-state-active' id='load_" + this.id + "'>" + this.p.loadtext + "</div>").insertBefore(gv);
			$(this).attr({
				cellspacing : "0",
				cellpadding : "0",
				border : "0",
				"role" : "grid",
				"aria-multiselectable" : !!this.p.multiselect,
				"aria-labelledby" : "gbox_" + this.id
			});
			var sortkeys = ["shiftKey", "altKey", "ctrlKey"],
			intNum = function (val, defval) {
				val = parseInt(val, 10);
				if (isNaN(val)) {
					return defval ? defval : 0;
				} else {
					return val;
				}
			},
			formatCol = function (pos, rowInd, tv) {
				var cm = ts.p.colModel[pos],
				ral = cm.align,
				result = "style=\"",
				clas = cm.classes,
				nm = cm.name;
				if (ral) {
					result += "text-align:" + ral + ";";
				}
				if (cm.hidden === true) {
					result += "display:none;";
				}
				if (rowInd === 0) {
					result += "width: " + grid.headers[pos].width + "px;";
				}
				result += "\"" + (clas !== undefined ? (" class=\"" + clas + "\"") : "");
				result += " aria-describedby=\"" + ts.p.id + "_" + nm + "\"";
				return result;
			},
			cellVal = function (val) {
				return val === undefined || val === null || val === "" ? "&#160;" : (ts.p.autoencode ? $.jgrid.htmlEncode(val) : val + "");
			},
			formatter = function (rowId, cellval, colpos, rwdat, _act) {
				var cm = ts.p.colModel[colpos],
				v;
				if (typeof cm.formatter !== 'undefined') {
					var opts = {
						rowId : rowId,
						colModel : cm,
						gid : ts.p.id
					};
					if ($.isFunction(cm.formatter)) {
						v = cm.formatter.call(ts, cellval, opts, rwdat, _act);
					} else if ($.fmatter) {
						v = $.fn.fmatter(cm.formatter, cellval, opts, rwdat, _act);
					} else {
						v = cellVal(cellval);
					}
				} else {
					v = cellVal(cellval);
				}
				return v;
			},
			addCell = function (rowId, cell, pos, irow, srvr) {
				var v,
				prp;
				v = formatter(rowId, cell, pos, srvr, 'add');
				prp = formatCol(pos, irow, v);
				return "<td role=\"gridcell\" " + prp + ">" + v + "</td>";
			},
			addMulti = function (rowid, pos, irow) {
				var v = "<input role=\"checkbox\" type=\"checkbox\"" + " id=\"jqg_" + ts.p.id + "_" + rowid + "\" onchange=\"checkboxchange()\" class=\"cbox\" name=\"jqg_" + ts.p.id + "_" + rowid + "\"/>",
				prp = formatCol(pos, irow, '');
				return "<td role=\"gridcell\" " + prp + ">" + v + "</td>";
			},
			addRowNum = function (pos, irow, pG, rN) {
				var v = (parseInt(pG, 10) - 1) * parseInt(rN, 10) + 1 + irow,
				prp = formatCol(pos, irow, '');
				return "<td role=\"gridcell\" class=\"ui-state-default jqgrid-rownum\" " + prp + ">" + v + "</td>";
			},
			reader = function (datatype) {
				var field,
				f = [],
				j = 0,
				i;
				for (i = 0; i < ts.p.colModel.length; i++) {
					field = ts.p.colModel[i];
					if (field.name !== 'cb' && field.name !== 'subgrid' && field.name !== 'rn') {
						if (datatype == "local") {
							f[j] = field.name;
						} else {
							f[j] = (datatype == "xml") ? field.xmlmap || field.name : field.jsonmap || field.name;
						}
						j++;
					}
				}
				return f;
			},
			orderedCols = function (offset) {
				var order = ts.p.remapColumns;
				if (!order || !order.length) {
					order = $.map(ts.p.colModel, function (v, i) {
							return i;
						});
				}
				if (offset) {
					order = $.map(order, function (v) {
							return v < offset ? null : v - offset;
						});
				}
				return order;
			},
			emptyRows = function (parent, scroll) {
				if (ts.p.deepempty) {
					$("#" + ts.p.id + " tbody:first tr:gt(0)").remove();
				} else {
					var trf = $("#" + ts.p.id + " tbody:first tr:first")[0];
					$("#" + ts.p.id + " tbody:first").empty().append(trf);
				}
				if (scroll && ts.p.scroll) {
					$(">div:first", parent).css({
						height : "auto"
					}).children("div:first").css({
						height : 0,
						display : "none"
					});
					parent.scrollTop = 0;
				}
			},
			refreshIndex = function () {
				var datalen = ts.p.data.length,
				idname,
				i,
				val,
				ni = ts.p.rownumbers === true ? 1 : 0,
				gi = ts.p.multiselect === true ? 1 : 0,
				si = ts.p.subGrid === true ? 1 : 0;
				if (ts.p.keyIndex === false || ts.p.loadonce === true) {
					idname = ts.p.localReader.id;
				} else {
					idname = ts.p.colModel[ts.p.keyIndex + gi + si + ni].name;
				}
				for (i = 0; i < datalen; i++) {
					val = $.jgrid.getAccessor(ts.p.data[i], idname);
					ts.p._index[val] = i;
				}
			},
			addXmlData = function (xml, t, rcnt, more, adjust) {
				var startReq = new Date(),
				locdata = (ts.p.datatype != "local" && ts.p.loadonce) || ts.p.datatype == "xmlstring",
				xmlid,
				frd = ts.p.datatype == "local" ? "local" : "xml";
				if (locdata) {
					ts.p.data = [];
					ts.p._index = {};
					ts.p.localReader.id = xmlid = "_id_";
				}
				ts.p.reccount = 0;
				if ($.isXMLDoc(xml)) {
					if (ts.p.treeANode === -1 && !ts.p.scroll) {
						emptyRows(t, false);
						rcnt = 1;
					} else {
						rcnt = rcnt > 1 ? rcnt : 1;
					}
				} else {
					return;
				}
				var i,
				fpos,
				ir = 0,
				v,
				row,
				gi = 0,
				si = 0,
				ni = 0,
				idn,
				getId,
				f = [],
				F,
				rd = {},
				xmlr,
				rid,
				rowData = [],
				cn = (ts.p.altRows === true) ? " " + ts.p.altclass : "",
				cn1;
				if (!ts.p.xmlReader.repeatitems) {
					f = reader(frd);
				}
				if (ts.p.keyIndex === false) {
					idn = ts.p.xmlReader.id;
				} else {
					idn = ts.p.keyIndex;
				}
				if (f.length > 0 && !isNaN(idn)) {
					if (ts.p.remapColumns && ts.p.remapColumns.length) {
						idn = $.inArray(idn, ts.p.remapColumns);
					}
					idn = f[idn];
				}
				if ((idn + "").indexOf("[") === -1) {
					if (f.length) {
						getId = function (trow, k) {
							return $(idn, trow).text() || k;
						};
					} else {
						getId = function (trow, k) {
							return $(ts.p.xmlReader.cell, trow).eq(idn).text() || k;
						};
					}
				} else {
					getId = function (trow, k) {
						return trow.getAttribute(idn.replace(/[\[\]]/g, "")) || k;
					};
				}
				ts.p.userData = {};
				$(ts.p.xmlReader.page, xml).each(function () {
					ts.p.page = this.textContent || this.text || 0;
				});
				$(ts.p.xmlReader.total, xml).each(function () {
					ts.p.lastpage = this.textContent || this.text;
					if (ts.p.lastpage === undefined) {
						ts.p.lastpage = 1;
					}
				});
				$(ts.p.xmlReader.records, xml).each(function () {
					ts.p.records = this.textContent || this.text || 0;
				});
				$(ts.p.xmlReader.userdata, xml).each(function () {
					ts.p.userData[this.getAttribute("name")] = this.textContent || this.text;
				});
				var gxml = $(ts.p.xmlReader.root + " " + ts.p.xmlReader.row, xml);
				if (!gxml) {
					gxml = [];
				}
				var gl = gxml.length,
				j = 0;
				if (gxml && gl) {
					var rn = parseInt(ts.p.rowNum, 10),
					br = ts.p.scroll ? (parseInt(ts.p.page, 10) - 1) * rn + 1 : 1,
					altr;
					if (adjust) {
						rn *= adjust + 1;
					}
					var afterInsRow = $.isFunction(ts.p.afterInsertRow),
					grpdata = {},
					hiderow = "";
					if (ts.p.grouping && ts.p.groupingView.groupCollapse === true) {
						hiderow = " style=\"display:none;\"";
					}
					while (j < gl) {
						xmlr = gxml[j];
						rid = getId(xmlr, br + j);
						altr = rcnt === 0 ? 0 : rcnt + 1;
						cn1 = (altr + j) % 2 == 1 ? cn : '';
						rowData.push("<tr" + hiderow + " id=\"" + rid + "\" role=\"row\" class =\"ui-widget-content jqgrow ui-row-" + ts.p.direction + "" + cn1 + "\">");
						if (ts.p.rownumbers === true) {
							rowData.push(addRowNum(0, j, ts.p.page, ts.p.rowNum));
							ni = 1;
						}
						if (ts.p.multiselect === true) {
							rowData.push(addMulti(rid, ni, j));
							gi = 1;
						}
						if (ts.p.subGrid === true) {
							rowData.push($(ts).jqGrid("addSubGridCell", gi + ni, j + rcnt));
							si = 1;
						}
						if (ts.p.xmlReader.repeatitems) {
							if (!F) {
								F = orderedCols(gi + si + ni);
							}
							var cells = $(ts.p.xmlReader.cell, xmlr);
							$.each(F, function (k) {
								var cell = cells[this];
								if (!cell) {
									return false;
								}
								v = cell.textContent || cell.text;
								rd[ts.p.colModel[k + gi + si + ni].name] = v;
								rowData.push(addCell(rid, v, k + gi + si + ni, j + rcnt, xmlr));
							});
						} else {
							for (i = 0; i < f.length; i++) {
								v = $(f[i], xmlr).text();
								rd[ts.p.colModel[i + gi + si + ni].name] = v;
								rowData.push(addCell(rid, v, i + gi + si + ni, j + rcnt, xmlr));
							}
						}
						rowData.push("</tr>");
						if (ts.p.grouping) {
							var grlen = ts.p.groupingView.groupField.length,
							grpitem = [];
							for (var z = 0; z < grlen; z++) {
								grpitem.push(rd[ts.p.groupingView.groupField[z]]);
							}
							grpdata = $(ts).jqGrid('groupingPrepare', rowData, grpitem, grpdata, rd);
							rowData = [];
						}
						if (locdata) {
							rd[xmlid] = rid;
							ts.p.data.push(rd);
						}
						if (ts.p.gridview === false) {
							if (ts.p.treeGrid === true) {
								fpos = ts.p.treeANode > -1 ? ts.p.treeANode : 0;
								row = $(rowData.join(''))[0];
								$(ts.rows[j + fpos]).after(row);
								try {
									$(ts).jqGrid("setTreeNode", rd, row);
								} catch (e) {}
								
							} else {
								$("tbody:first", t).append(rowData.join(''));
							}
							if (ts.p.subGrid === true) {
								try {
									$(ts).jqGrid("addSubGrid", ts.rows[ts.rows.length - 1], gi + ni);
								} catch (_) {}
								
							}
							if (afterInsRow) {
								ts.p.afterInsertRow.call(ts, rid, rd, xmlr);
							}
							rowData = [];
						}
						rd = {};
						ir++;
						j++;
						if (ir == rn) {
							break;
						}
					}
				}
				if (ts.p.gridview === true) {
					if (ts.p.grouping) {
						$(ts).jqGrid('groupingRender', grpdata, ts.p.colModel.length);
						grpdata = null;
					} else {
						$("tbody:first", t).append(rowData.join(''));
					}
				}
				ts.p.totaltime = new Date() - startReq;
				if (ir > 0) {
					if (ts.p.records === 0) {
						ts.p.records = gl;
					}
				}
				rowData = null;
				if (!ts.p.treeGrid && !ts.p.scroll) {
					ts.grid.bDiv.scrollTop = 0;
				}
				ts.p.reccount = ir;
				ts.p.treeANode = -1;
				if (ts.p.userDataOnFooter) {
					$(ts).jqGrid("footerData", "set", ts.p.userData, true);
				}
				if (locdata) {
					ts.p.records = gl;
					ts.p.lastpage = Math.ceil(gl / rn);
				}
				if (!more) {
					ts.updatepager(false, true);
				}
				if (locdata) {
					while (ir < gl) {
						xmlr = gxml[ir];
						rid = getId(xmlr, ir);
						if (ts.p.xmlReader.repeatitems) {
							if (!F) {
								F = orderedCols(gi + si + ni);
							}
							var cells2 = $(ts.p.xmlReader.cell, xmlr);
							$.each(F, function (k) {
								var cell = cells2[this];
								if (!cell) {
									return false;
								}
								v = cell.textContent || cell.text;
								rd[ts.p.colModel[k + gi + si + ni].name] = v;
							});
						} else {
							for (i = 0; i < f.length; i++) {
								v = $(f[i], xmlr).text();
								rd[ts.p.colModel[i + gi + si + ni].name] = v;
							}
						}
						rd[xmlid] = rid;
						ts.p.data.push(rd);
						rd = {};
						ir++;
					}
					refreshIndex();
				}
			},
			addJSONData = function (data, t, rcnt, more, adjust) {
				var startReq = new Date();
				if (data) {
					if (ts.p.treeANode === -1 && !ts.p.scroll) {
						emptyRows(t, false);
						rcnt = 1;
					} else {
						rcnt = rcnt > 1 ? rcnt : 1;
					}
				} else {
					return;
				}
				var dReader,
				locid,
				frd,
				locdata = (ts.p.datatype != "local" && ts.p.loadonce) || ts.p.datatype == "jsonstring";
				if (locdata) {
					ts.p.data = [];
					ts.p._index = {};
					locid = ts.p.localReader.id = "_id_";
				}
				ts.p.reccount = 0;
				if (ts.p.datatype == "local") {
					dReader = ts.p.localReader;
					frd = 'local';
				} else {
					dReader = ts.p.jsonReader;
					frd = 'json';
				}
				var ir = 0,
				v,
				i,
				j,
				row,
				f = [],
				F,
				cur,
				gi = 0,
				si = 0,
				ni = 0,
				len,
				drows,
				idn,
				rd = {},
				fpos,
				idr,
				rowData = [],
				cn = (ts.p.altRows === true) ? " " + ts.p.altclass : "",
				cn1,
				lp;
				ts.p.page = $.jgrid.getAccessor(data, dReader.page) || 0;
				lp = $.jgrid.getAccessor(data, dReader.total);
				ts.p.lastpage = lp === undefined ? 1 : lp;
				ts.p.records = $.jgrid.getAccessor(data, dReader.records) || 0;
				ts.p.userData = $.jgrid.getAccessor(data, dReader.userdata) || {};
				if (!dReader.repeatitems) {
					F = f = reader(frd);
				}
				if (ts.p.keyIndex === false) {
					idn = dReader.id;
				} else {
					idn = ts.p.keyIndex;
				}
				if (f.length > 0 && !isNaN(idn)) {
					if (ts.p.remapColumns && ts.p.remapColumns.length) {
						idn = $.inArray(idn, ts.p.remapColumns);
					}
					idn = f[idn];
				}
				drows = $.jgrid.getAccessor(data, dReader.root);
				if (!drows) {
					drows = [];
				}
				len = drows.length;
				i = 0;
				var rn = parseInt(ts.p.rowNum, 10),
				br = ts.p.scroll ? (parseInt(ts.p.page, 10) - 1) * rn + 1 : 1,
				altr;
				if (adjust) {
					rn *= adjust + 1;
				}
				var afterInsRow = $.isFunction(ts.p.afterInsertRow),
				grpdata = {},
				hiderow = "";
				if (ts.p.grouping && ts.p.groupingView.groupCollapse === true) {
					hiderow = " style=\"display:none;\"";
				}
				while (i < len) {
					cur = drows[i];
					idr = $.jgrid.getAccessor(cur, idn);
					if (idr === undefined) {
						idr = br + i;
						if (f.length === 0) {
							if (dReader.cell) {
								var ccur = cur[dReader.cell];
								idr = ccur[idn] || idr;
								ccur = null;
							}
						}
					}
					altr = rcnt === 1 ? 0 : rcnt;
					cn1 = (altr + i) % 2 == 1 ? cn : '';
					rowData.push("<tr" + hiderow + " id=\"" + idr + "\" role=\"row\" onclick=\"salemancheck('" + ts.p.id + "','" + idr + "')\"class= \"ui-widget-content jqgrow ui-row-" + ts.p.direction + "" + cn1 + "\">");
					if (ts.p.rownumbers === true) {
						rowData.push(addRowNum(0, i, ts.p.page, ts.p.rowNum));
						ni = 1;
					}
					if (ts.p.multiselect) {
						rowData.push(addMulti(idr, ni, i));
						gi = 1;
					}
					if (ts.p.subGrid) {
						rowData.push($(ts).jqGrid("addSubGridCell", gi + ni, i + rcnt));
						si = 1;
					}
					if (dReader.repeatitems) {
						if (dReader.cell) {
							cur = $.jgrid.getAccessor(cur, dReader.cell);
						}
						if (!F) {
							F = orderedCols(gi + si + ni);
						}
					}
					for (j = 0; j < F.length; j++) {
						v = $.jgrid.getAccessor(cur, F[j]);
						rowData.push(addCell(idr, v, j + gi + si + ni, i + rcnt, cur));
						rd[ts.p.colModel[j + gi + si + ni].name] = v;
					}
					rowData.push("</tr>");
					if (ts.p.grouping) {
						var grlen = ts.p.groupingView.groupField.length,
						grpitem = [];
						for (var z = 0; z < grlen; z++) {
							grpitem.push(rd[ts.p.groupingView.groupField[z]]);
						}
						grpdata = $(ts).jqGrid('groupingPrepare', rowData, grpitem, grpdata, rd);
						rowData = [];
					}
					if (locdata) {
						rd[locid] = idr;
						ts.p.data.push(rd);
					}
					if (ts.p.gridview === false) {
						if (ts.p.treeGrid === true) {
							fpos = ts.p.treeANode > -1 ? ts.p.treeANode : 0;
							row = $(rowData.join(''))[0];
							$(ts.rows[i + fpos]).after(row);
							try {
								$(ts).jqGrid("setTreeNode", rd, row);
							} catch (e) {}
							
						} else {
							$("#" + ts.p.id + " tbody:first").append(rowData.join(''));
						}
						if (ts.p.subGrid === true) {
							try {
								$(ts).jqGrid("addSubGrid", ts.rows[ts.rows.length - 1], gi + ni);
							} catch (_) {}
							
						}
						if (afterInsRow) {
							ts.p.afterInsertRow.call(ts, idr, rd, cur);
						}
						rowData = [];
					}
					rd = {};
					ir++;
					i++;
					if (ir == rn) {
						break;
					}
				}
				if (ts.p.gridview === true) {
					if (ts.p.grouping) {
						$(ts).jqGrid('groupingRender', grpdata, ts.p.colModel.length);
						grpdata = null;
					} else {
						$("#" + ts.p.id + " tbody:first").append(rowData.join(''));
					}
				}
				ts.p.totaltime = new Date() - startReq;
				if (ir > 0) {
					if (ts.p.records === 0) {
						ts.p.records = len;
					}
				}
				rowData = null;
				if (!ts.p.treeGrid && !ts.p.scroll) {
					ts.grid.bDiv.scrollTop = 0;
				}
				ts.p.reccount = ir;
				ts.p.treeANode = -1;
				if (ts.p.userDataOnFooter) {
					$(ts).jqGrid("footerData", "set", ts.p.userData, true);
				}
				if (locdata) {
					ts.p.records = len;
					ts.p.lastpage = Math.ceil(len / rn);
				}
				if (!more) {
					ts.updatepager(false, true);
				}
				if (locdata) {
					while (ir < len) {
						cur = drows[ir];
						idr = $.jgrid.getAccessor(cur, idn);
						if (idr === undefined) {
							idr = br + ir;
							if (f.length === 0) {
								if (dReader.cell) {
									var ccur2 = cur[dReader.cell];
									idr = ccur2[idn] || idr;
									ccur2 = null;
								}
							}
						}
						if (cur) {
							if (dReader.repeatitems) {
								if (dReader.cell) {
									cur = $.jgrid.getAccessor(cur, dReader.cell);
								}
								if (!F) {
									F = orderedCols(gi + si + ni);
								}
							}
							for (j = 0; j < F.length; j++) {
								v = $.jgrid.getAccessor(cur, F[j]);
								rd[ts.p.colModel[j + gi + si + ni].name] = v;
							}
							rd[locid] = idr;
							ts.p.data.push(rd);
							rd = {};
						}
						ir++;
					}
					refreshIndex();
				}
			},
			addLocalData = function () {
				var st,
				fndsort = false,
				cmtypes = [],
				grtypes = [],
				srcformat,
				sorttype,
				newformat;
				if (!$.isArray(ts.p.data)) {
					return;
				}
				var grpview = ts.p.grouping ? ts.p.groupingView : false;
				$.each(ts.p.colModel, function (i, v) {
					sorttype = this.sorttype || "text";
					if (sorttype == "date" || sorttype == "datetime") {
						if (this.formatter && typeof(this.formatter) === 'string' && this.formatter == 'date') {
							if (this.formatoptions && this.formatoptions.srcformat) {
								srcformat = this.formatoptions.srcformat;
							} else {
								srcformat = $.jgrid.formatter.date.srcformat;
							}
							if (this.formatoptions && this.formatoptions.newformat) {
								newformat = this.formatoptions.newformat;
							} else {
								newformat = $.jgrid.formatter.date.newformat;
							}
						} else {
							srcformat = newformat = this.datefmt || "Y-m-d";
						}
						cmtypes[this.name] = {
							"stype" : sorttype,
							"srcfmt" : srcformat,
							"newfmt" : newformat
						};
					} else {
						cmtypes[this.name] = {
							"stype" : sorttype,
							"srcfmt" : '',
							"newfmt" : ''
						};
					}
					if (ts.p.grouping && this.name == grpview.groupField[0]) {
						grtypes[0] = cmtypes[this.name];
					}
					if (!fndsort && (this.index == ts.p.sortname || this.name == ts.p.sortname)) {
						st = this.name;
						fndsort = true;
					}
				});
				if (ts.p.treeGrid) {
					$(ts).jqGrid("SortTree", st, ts.p.sortorder, cmtypes[st].stype, cmtypes[st].srcfmt);
					return;
				}
				var compareFnMap = {
					'eq' : function (queryObj) {
						return queryObj.equals;
					},
					'ne' : function (queryObj) {
						return queryObj.not().equals;
					},
					'lt' : function (queryObj) {
						return queryObj.less;
					},
					'le' : function (queryObj) {
						return queryObj.lessOrEquals;
					},
					'gt' : function (queryObj) {
						return queryObj.greater;
					},
					'ge' : function (queryObj) {
						return queryObj.greaterOrEquals;
					},
					'cn' : function (queryObj) {
						return queryObj.contains;
					},
					'nc' : function (queryObj) {
						return queryObj.not().contains;
					},
					'bw' : function (queryObj) {
						return queryObj.startsWith;
					},
					'bn' : function (queryObj) {
						return queryObj.not().startsWith;
					},
					'en' : function (queryObj) {
						return queryObj.not().endsWith;
					},
					'ew' : function (queryObj) {
						return queryObj.endsWith;
					},
					'ni' : function (queryObj) {
						return queryObj.not().equals;
					},
					'in' : function (queryObj) {
						return queryObj.equals;
					}
				},
				query = $.jgrid.from(ts.p.data);
				if (ts.p.ignoreCase) {
					query = query.ignoreCase();
				}
				if (ts.p.search === true) {
					var srules = ts.p.postData.filters,
					opr;
					if (srules) {
						if (typeof srules == "string") {
							srules = $.jgrid.parse(srules);
						}
						for (var i = 0, l = srules.rules.length, rule; i < l; i++) {
							rule = srules.rules[i];
							opr = srules.groupOp;
							if (compareFnMap[rule.op] && rule.field && rule.data && opr) {
								if (opr.toUpperCase() == "OR") {
									query = compareFnMap[rule.op](query)(rule.field, rule.data, cmtypes[rule.field]).or();
								} else {
									query = compareFnMap[rule.op](query)(rule.field, rule.data, cmtypes[rule.field]);
								}
							}
						}
					} else {
						try {
							query = compareFnMap[ts.p.postData.searchOper](query)(ts.p.postData.searchField, ts.p.postData.searchString, cmtypes[ts.p.postData.searchField]);
						} catch (se) {}
						
					}
				}
				if (ts.p.grouping) {
					query.orderBy(grpview.groupField[0], grpview.groupOrder[0], grtypes[0].stype, grtypes[0].srcfmt);
					grpview.groupDataSorted = true;
				}
				if (st && ts.p.sortorder && fndsort) {
					if (ts.p.sortorder.toUpperCase() == "DESC") {
						query.orderBy(ts.p.sortname, "d", cmtypes[st].stype, cmtypes[st].srcfmt);
					} else {
						query.orderBy(ts.p.sortname, "a", cmtypes[st].stype, cmtypes[st].srcfmt);
					}
				}
				var queryResults = query.select(),
				recordsperpage = parseInt(ts.p.rowNum, 10),
				total = queryResults.length,
				page = parseInt(ts.p.page, 10),
				totalpages = Math.ceil(total / recordsperpage),
				retresult = {};
				queryResults = queryResults.slice((page - 1) * recordsperpage, page * recordsperpage);
				query = null;
				cmtypes = null;
				retresult[ts.p.localReader.total] = totalpages;
				retresult[ts.p.localReader.page] = page;
				retresult[ts.p.localReader.records] = total;
				retresult[ts.p.localReader.root] = queryResults;
				queryResults = null;
				return retresult;
			},
			updatepager = function (rn, dnd) {
				var cp, last, base, from,to,tot,fmt, pgboxes = "", sppg,
				tspg = ts.p.pager ? "_"+$.jgrid.jqID(ts.p.pager.substr(1)) : "",
				tspg_t = ts.p.toppager ? "_"+ts.p.toppager.substr(1) : "";
				
				base = parseInt(ts.p.page, 10) - 1;
				if (base < 0) {
					base = 0;
				}
				base = base * parseInt(ts.p.rowNum, 10);
				to = base + ts.p.reccount;
				if (ts.p.scroll) {
					var rows = $("tbody:first > tr:gt(0)", ts.grid.bDiv);
					base = to - rows.length;
					ts.p.reccount = rows.length;
					var rh = rows.outerHeight() || ts.grid.prevRowHeight;
					if (rh) {
						var top = base * rh;
						var height = parseInt(ts.p.records, 10) * rh;
						$(">div:first", ts.grid.bDiv).css({
							height : height
						}).children("div:first").css({
							height : top,
							display : top ? "" : "none"
						});
					}
					ts.grid.bDiv.scrollLeft = ts.grid.hDiv.scrollLeft;
				}
				pgboxes = ts.p.pager ? ts.p.pager : "";
				pgboxes += ts.p.toppager ? (pgboxes ? "," + ts.p.toppager : ts.p.toppager) : "";
				if (pgboxes) {
					fmt = $.jgrid.formatter.integer || {};
					cp = intNum(ts.p.page);
					last = intNum(ts.p.lastpage);
					$(".selbox",pgboxes)[ this.p.useProp ? 'prop' : 'attr' ]("disabled",false);
					if(ts.p.pginput===true) {
						$('.ui-pg-input',pgboxes).val(ts.p.page);
						sppg = ts.p.toppager ? '#sp_1'+tspg+",#sp_1"+tspg_t : '#sp_1'+tspg;
						$(sppg).html($.fmatter ? $.fmatter.util.NumberFormat(ts.p.lastpage,fmt):ts.p.lastpage);

					}
					
					if (ts.p.viewrecords) {
						if (ts.p.reccount === 0) {
							$("#fhxtdput", pgboxes).html(ts.p.emptyrecords);
						} else {
							from = base + 1;
							tot = ts.p.records;
							if ($.fmatter) {
								from = $.fmatter.util.NumberFormat(from, fmt);
								to = $.fmatter.util.NumberFormat(to, fmt);
								tot = $.fmatter.util.NumberFormat(tot, fmt);
							}
							$("#fhxtdput", pgboxes).html($.jgrid.format(ts.p.recordtext, from, to, tot));
						}
						$(".ui-paging-info", pgboxes).html('');
					}
					if (ts.p.pgbuttons === true) {
						if (cp <= 0) {
							cp = last = 0;
						}
						if (cp == 1 || cp === 0) {
							$("#prev", ts.p.pager).html('上一页');
							$("#first", ts.p.pager).html('首页');
							$("#first, #prev", ts.p.pager).removeClass('ui-state-hover');
							if (ts.p.toppager) {
								$("#prev_t", ts.p.pager).html('上一页');
								$("#first_t", ts.p.pager).html('首页');
								$("#first_t, #prev_t", ts.p.pager).removeClass('ui-state-hover');
							}
						} else {
							$("#prev", ts.p.pager).html('<a href="javascript:">上一页</a>');
							$("#first", ts.p.pager).html('<a href="javascript:">首页</a>');
							if (ts.p.toppager) {
								$("#prev_t", ts.p.pager).html('<a href="javascript:">上一页</a>');
								$("#first_t", ts.p.pager).html('<a href="javascript:">首页</a>');
							}
						}
						if (cp == last || cp === 0) {
							$("#next", ts.p.pager).html('下一页');
							$("#last", ts.p.pager).html('尾页');
							$("#last, #next", ts.p.pager).removeClass('ui-state-hover');
							if (ts.p.toppager) {
								$("#next_t", ts.p.pager).html('下一页');
								$("#last_t", ts.p.pager).html('尾页');
								$("#last_t, #next_t", ts.p.pager).removeClass('ui-state-hover');
							}
						} else {
							$("#next", ts.p.pager).html('<a href="javascript:">下一页</a>');
							$("#last", ts.p.pager).html('<a href="javascript:">尾页</a>');
							if (ts.p.toppager) {
								$("#next_t", ts.p.pager).html('<a href="javascript:">下一页</a>');
								$("#last_t", ts.p.pager).html('<a href="javascript:">尾页</a>');
							}
						}
					}
				}
				if (rn === true && ts.p.rownumbers === true) {
					$("td.jqgrid-rownum", ts.rows).each(function (i) {
						$(this).html(base + 1 + i);
					});
				}
				if (dnd && ts.p.jqgdnd) {
					$(ts).jqGrid('gridDnD', 'updateDnD');
				}
				if ($.isFunction(ts.p.gridComplete)) {
					ts.p.gridComplete.call(ts);
				}
			},
			beginReq = function () {
				ts.grid.hDiv.loading = true;
				if (ts.p.hiddengrid) {
					return;
				}
				switch (ts.p.loadui) {
				case "disable":
					break;
				case "enable":
					$("#load_" + ts.p.id).show();
					break;
				case "block":
					$("#lui_" + ts.p.id).show();
					$("#load_" + ts.p.id).show();
					break;
				}
			},
			endReq = function () {
				ts.grid.hDiv.loading = false;
				switch (ts.p.loadui) {
				case "disable":
					break;
				case "enable":
					$("#load_" + ts.p.id).hide();
					break;
				case "block":
					$("#lui_" + ts.p.id).hide();
					$("#load_" + ts.p.id).hide();
					break;
				}
			},
			populate = function (npage) {
				if (!ts.grid.hDiv.loading) {
					var pvis = ts.p.scroll && npage === false;
					var prm = {},
					dt,
					dstr,
					pN = ts.p.prmNames;
					if (ts.p.page <= 0) {
						ts.p.page = 1;
					}
					if (pN.search !== null) {
						prm[pN.search] = ts.p.search;
					}
					if (pN.nd !== null) {
						prm[pN.nd] = new Date().getTime();
					}
					if (pN.rows !== null) {
						prm[pN.rows] = ts.p.rowNum;
					}
					if (pN.page !== null) {
						prm[pN.page] = ts.p.page;
					}
					if (pN.sort !== null) {
						prm[pN.sort] = ts.p.sortname;
					}
					if (pN.order !== null) {
						prm[pN.order] = ts.p.sortorder;
					}
					if (ts.p.rowTotal !== null && pN.totalrows !== null) {
						prm[pN.totalrows] = ts.p.rowTotal;
					}
					var lc = ts.p.loadComplete;
					var lcf = $.isFunction(lc);
					if (!lcf) {
						lc = null;
					}
					var adjust = 0;
					npage = npage || 1;
					if (npage > 1) {
						if (pN.npage !== null) {
							prm[pN.npage] = npage;
							adjust = npage - 1;
							npage = 1;
						} else {
							lc = function (req) {
								ts.p.page++;
								ts.grid.hDiv.loading = false;
								if (lcf) {
									ts.p.loadComplete.call(ts, req);
								}
								populate(npage - 1);
							};
						}
					} else if (pN.npage !== null) {
						delete ts.p.postData[pN.npage];
					}
					if (ts.p.grouping) {
						$(ts).jqGrid('groupingSetup');
						if (ts.p.groupingView.groupDataSorted === true) {
							prm[pN.sort] = ts.p.groupingView.groupField[0] + " " + ts.p.groupingView.groupOrder[0] + ", " + prm[pN.sort];
						}
					}
					$.extend(ts.p.postData, prm);
					var rcnt = !ts.p.scroll ? 1 : ts.rows.length - 1;
					if ($.isFunction(ts.p.datatype)) {
						ts.p.datatype.call(ts, ts.p.postData, "load_" + ts.p.id);
						return;
					} else if ($.isFunction(ts.p.beforeRequest)) {
						ts.p.beforeRequest.call(ts);
					}
					dt = ts.p.datatype.toLowerCase();
					switch (dt) {
					case "json":
					case "jsonp":
					case "xml":
					case "script":
						$.ajax($.extend({
								url : ts.p.url,
								type : ts.p.mtype,
								dataType : dt,
								data : $.isFunction(ts.p.serializeGridData) ? ts.p.serializeGridData.call(ts, ts.p.postData) : ts.p.postData,
								success : function (data, st) {
									if (dt === "xml") {
										addXmlData(data, ts.grid.bDiv, rcnt, npage > 1, adjust);
									} else {
										addJSONData(data, ts.grid.bDiv, rcnt, npage > 1, adjust);
									}
									if (lc) {
										lc.call(ts, data);
									}
									if (pvis) {
										ts.grid.populateVisible();
									}
									if (ts.p.loadonce || ts.p.treeGrid) {
										ts.p.datatype = "local";
									}
									data = null;
									endReq();
								},
								error : function (xhr, st, err) {
									if ($.isFunction(ts.p.loadError)) {
										ts.p.loadError.call(ts, xhr, st, err);
									}
									endReq();
									xhr = null;
								},
								beforeSend : function (xhr) {
									beginReq();
									if ($.isFunction(ts.p.loadBeforeSend)) {
										ts.p.loadBeforeSend.call(ts, xhr);
									}
								}
							}, $.jgrid.ajaxOptions, ts.p.ajaxGridOptions));
						break;
					case "xmlstring":
						beginReq();
						dstr = $.jgrid.stringToDoc(ts.p.datastr);
						addXmlData(dstr, ts.grid.bDiv);
						if (lcf) {
							ts.p.loadComplete.call(ts, dstr);
						}
						ts.p.datatype = "local";
						ts.p.datastr = null;
						endReq();
						break;
					case "jsonstring":
						beginReq();
						if (typeof ts.p.datastr == 'string') {
							dstr = $.jgrid.parse(ts.p.datastr);
						} else {
							dstr = ts.p.datastr;
						}
						addJSONData(dstr, ts.grid.bDiv);
						if (lcf) {
							ts.p.loadComplete.call(ts, dstr);
						}
						ts.p.datatype = "local";
						ts.p.datastr = null;
						endReq();
						break;
					case "local":
					case "clientside":
						beginReq();
						ts.p.datatype = "local";
						var req = addLocalData();
						addJSONData(req, ts.grid.bDiv, rcnt, npage > 1, adjust);
						if (lc) {
							lc.call(ts, req);
						}
						if (pvis) {
							ts.grid.populateVisible();
						}
						endReq();
						break;
					}
				}
			},
			setPager = function (pgid, tp) {
				var sep = "",
				pginp = "",
				pgl = "<table cellspacing='0' cellpadding='0' border='0' style='table-layout:auto;' class='ui-pg-table'><tbody><tr>",
				str = "",
				pgcnt,
				lft,
				cent,
				rgt,
				twd,
				tdw,
				i,
				clearVals = function (onpaging) {
					var ret;
					if ($.isFunction(ts.p.onPaging)) {
						ret = ts.p.onPaging.call(ts, onpaging);
					}
					ts.p.selrow = null;
					if (ts.p.multiselect) {
						ts.p.selarrrow = [];
						$('#cb_' + $.jgrid.jqID(ts.p.id), ts.grid.hDiv).attr("checked", false);
					}
					ts.p.savedRow = [];
					if (ret == 'stop') {
						return false;
					}
					return true;
				};
				pgid = pgid.substr(1);
				pgcnt = "pg_" + pgid;
				lft = pgid + "_left";
				cent = pgid + "_center";
				rgt = pgid + "_right";
				$("#" + pgid).append("<div id='" + pgcnt + "' class='ui-pager-control' role='group'><table cellspacing='0' cellpadding='0' border='0' class='ui-pg-table' style=':100%;table-layout:fixed;height:100%;' role='row'><tbody><tr><td id='" + lft + "' align='left' width=42%></td><td id='" + rgt + "' align='center' width=3%></td><td  id='" + cent + "' align='right' style='white-space:pre;'></td></tr></tbody></table></div>").attr("dir", "ltr");
				if (ts.p.rowList.length > 0) {
					str = "<td id='fhxtdput'></td><td >&nbsp;每页</td><td dir='" + dir + "'>";
					str += "<select class='ui-pg-selbox' role='listbox'>";
					for (i = 0; i < ts.p.rowList.length; i++) {
						str += "<option role=\"option\" value=\"" + ts.p.rowList[i] + "\"" + ((ts.p.rowNum == ts.p.rowList[i]) ? " selected=\"selected\"" : "") + ">" + ts.p.rowList[i] + "</option>";
					}
					str += "</select>条&nbsp;&nbsp;</td>";
				}
				if (dir == "rtl") {
					pgl += str;
				}
				
				if(ts.p.pginput===true) { pginp= "<td dir='"+dir+"'>"+$.jgrid.format(ts.p.pgtext || "","<input class='ui-pg-input' type='text' size='2' maxlength='7' value='0' role='textbox'/>","<span id='sp_1_"+$.jgrid.jqID(pgid)+"'></span>")+"</td>";}

				if (dir == "ltr") {
					pgl += str;
				}
				if (ts.p.pgbuttons === true) {
					var po = ["first" + tp, "prev" + tp, "next" + tp, "last" + tp];
					if (dir == "rtl") {
						po.reverse();
					}
					pgl += "<td id='" + po[0] + "' class=''><a href='javascript:'>首页</a></td>";
					pgl += "<td id='" + po[1] + "' class=''><a href='javascript:'>上一页</a></td>";
					pgl += "<td id='" + po[2] + "' class=''><a href='javascript:'>下一页</a></td>";
					pgl += "<td id='" + po[3] + "' class=''><a href='javascript:'>尾页</a></td>";
					pgl += pginp !== "" ? sep + pginp + sep : "";
				} else if (pginp !== "") {
					pgl += pginp;
				}
				pgl += "</tr></tbody></table>";
				if (ts.p.viewrecords === true) {
					$("td#" + pgid + "_" + ts.p.recordpos, "#" + pgcnt).append("<div dir='" + dir + "' style='text-align:" + ts.p.recordpos + "' class='ui-paging-info'></div>");
				}
				$("td#" + pgid + "_" + ts.p.pagerpos, "#" + pgcnt).append(pgl);
				tdw = $(".ui-jqgrid").css("font-size") || "11px";
				$(document.body).append("<div id='testpg' class='ui-jqgrid ui-widget ui-widget-content' style='font-size:" + tdw + ";visibility:hidden;' ></div>");
				twd = $(pgl).clone().appendTo("#testpg").width();
				$("#testpg").remove();
				if (twd > 0) {
					if (pginp != "") {
						twd += 110; //mayi
					}
					$("td#" + pgid + "_" + ts.p.pagerpos, "#" + pgcnt).width(twd);
				}
				ts.p._nvtd = [];
				ts.p._nvtd[0] = twd ? Math.floor((ts.p.width - twd) / 2) : Math.floor(ts.p.width / 3);
				ts.p._nvtd[1] = 0;
				pgl = null;
				$('.ui-pg-selbox', "#" + pgcnt).bind('change', function () {
					ts.p.page = Math.round(ts.p.rowNum * (ts.p.page - 1) / this.value - 0.5) + 1;
					ts.p.rowNum = this.value;
					if (tp) {
						$('.ui-pg-selbox', ts.p.pager).val(this.value);
					} else if (ts.p.toppager) {
						$('.ui-pg-selbox', ts.p.toppager).val(this.value);
					}
					if (!clearVals('records')) {
						return false;
					}
					populate();
					return false;
				});
				if (ts.p.pgbuttons === true) {
					$(".ui-pg-button", "#" + pgcnt).hover(function (e) {
						if ($(this).hasClass('ui-state-disabled')) {
							this.style.cursor = 'default';
						} else {
							$(this).addClass('ui-state-cnzz');
							this.style.cursor = 'pointer';
						}
					}, function (e) {
						if ($(this).hasClass('ui-state-disabled')) {}
						else {
							$(this).removeClass('ui-state-hover');
							this.style.cursor = "default";
						}
					});
					$("#first" + tp + ", #prev" + tp + ", #next" + tp + ", #last" + tp, "#" + pgid).click(function (e) {
						var cp = intNum(ts.p.page, 1),
						last = intNum(ts.p.lastpage, 1),
						selclick = false,
						fp = true,
						pp = true,
						np = true,
						lp = true;
						if (last === 0 || last === 1) {
							fp = false;
							pp = false;
							np = false;
							lp = false;
						} else if (last > 1 && cp >= 1) {
							if (cp === 1) {
								fp = false;
								pp = false;
							} else if (cp > 1 && cp < last) {}
							else if (cp === last) {
								np = false;
								lp = false;
							}
						} else if (last > 1 && cp === 0) {
							np = false;
							lp = false;
							cp = last - 1;
						}
						if (this.id === 'first' + tp && fp) {
							ts.p.page = 1;
							selclick = true;
						}
						if (this.id === 'prev' + tp && pp) {
							ts.p.page = (cp - 1);
							selclick = true;
						}
						if (this.id === 'next' + tp && np) {
							ts.p.page = (cp + 1);
							selclick = true;
						}
						if (this.id === 'last' + tp && lp) {
							ts.p.page = last;
							selclick = true;
						}
						if (selclick) {
							if (!clearVals(this.id)) {
								return false;
							}
							populate();
						}
						return false;
					});
				}
				if(ts.p.pginput===true) {
					$('input.ui-pg-input',"#"+pgcnt).keypress( function(e) {
						var key = e.charCode || e.keyCode || 0;
						if(key == 13) {
							if(!clearVals('user')) { return false; }
							ts.p.page = ($(this).val()>0) ? $(this).val():ts.p.page;
							populate();
							return false;
						}
						return this;
					});
					}
			},
			sortData = function (index, idxcol, reload, sor) {
				if (!ts.p.colModel[idxcol].sortable) {
					return;
				}
				var so;
				if (ts.p.savedRow.length > 0) {
					return;
				}
				if (!reload) {
					if (ts.p.lastsort == idxcol) {
						if (ts.p.sortorder == 'asc') {
							ts.p.sortorder = 'desc';
						} else if (ts.p.sortorder == 'desc') {
							ts.p.sortorder = 'asc';
						}
					} else {
						ts.p.sortorder = ts.p.colModel[idxcol].firstsortorder || 'asc';
					}
					ts.p.page = 1;
				}
				if (sor) {
					if (ts.p.lastsort == idxcol && ts.p.sortorder == sor && !reload) {
						return;
					} else {
						ts.p.sortorder = sor;
					}
				}
				var thd = $("thead:first", ts.grid.hDiv).get(0);
				$("tr th:eq(" + ts.p.lastsort + ") span.ui-grid-ico-sort", thd).addClass('ui-state-disabled');
				$("tr th:eq(" + ts.p.lastsort + ")", thd).attr("aria-selected", "false");
				$("tr th:eq(" + idxcol + ") span.ui-icon-" + ts.p.sortorder, thd).removeClass('ui-state-disabled');
				$("tr th:eq(" + idxcol + ")", thd).attr("aria-selected", "true");
				if (!ts.p.viewsortcols[0]) {
					$('img[name=updownimg]').attr('src', contextPath + '/images/arrow_n.gif');
					if (ts.p.lastsort != idxcol) {
						if (ts.p.sortorder == 'asc')
							$("tr th:eq(" + idxcol + ") span.s-ico", thd).html("<img src='" + contextPath + "/images/arrow_up.gif' style='position:absolute;bottom:9px;padding-left:2px' name='updownimg' />");
						else
							$("tr th:eq(" + idxcol + ") span.s-ico", thd).html("<img src='" + contextPath + "/images/arrow_down.gif' style='position:absolute;bottom:9px;padding-left:2px' name='updownimg' />");
					} else {
						if (ts.p.sortorder == 'asc')
							$("tr th:eq(" + idxcol + ") span.s-ico", thd).html("<img src='" + contextPath + "/images/arrow_up.gif' style='position:absolute;bottom:9px;padding-left:2px' name='updownimg' />");
						else
							$("tr th:eq(" + idxcol + ") span.s-ico", thd).html("<img src='" + contextPath + "/images/arrow_down.gif' style='position:absolute;bottom:9px;padding-left:2px' name='updownimg' />");
					}
				}
				index = index.substring(5);
				ts.p.sortname = ts.p.colModel[idxcol].index || index;
				so = ts.p.sortorder;
				if ($.isFunction(ts.p.onSortCol)) {
					if (ts.p.onSortCol.call(ts, index, idxcol, so) == 'stop') {
						ts.p.lastsort = idxcol;
						return;
					}
				}
				if (ts.p.datatype == "local") {
					if (ts.p.deselectAfterSort) {
						$(ts).jqGrid("resetSelection");
					}
				} else {
					ts.p.selrow = null;
					if (ts.p.multiselect) {
						$("#cb_" + $.jgrid.jqID(ts.p.id), ts.grid.hDiv).attr("checked", false);
					}
					ts.p.selarrrow = [];
					ts.p.savedRow = [];
				}
				if (ts.p.scroll) {
					var sscroll = ts.grid.bDiv.scrollLeft;
					emptyRows(ts.grid.bDiv, true);
					ts.grid.hDiv.scrollLeft = sscroll;
				}
				if (ts.p.subGrid && ts.p.datatype == 'local') {
					$("td.sgexpanded", "#" + ts.p.id).each(function () {
						$(this).trigger("click");
					});
				}
				populate();
				ts.p.lastsort = idxcol;
				if (ts.p.sortname != index && idxcol) {
					ts.p.lastsort = idxcol;
				}
			},
			setColWidth = function () {
				var initwidth = 0,
				brd = ts.p.cellLayout,
				vc = 0,
				lvc,
				scw = ts.p.scrollOffset,
				cw,
				hs = false,
				aw,
				tw = 0,
				gw = 0,
				cl = 0,
				cr;
				if (isSafari) {
					brd = 0;
				}
				$.each(ts.p.colModel, function (i) {
					if (typeof this.hidden === 'undefined') {
						this.hidden = false;
					}
					if (this.hidden === false) {
						initwidth += intNum(this.width, 0);
						if (this.fixed) {
							tw += this.width;
							gw += this.width + brd;
						} else {
							vc++;
						}
						cl++;
					}
				});
				if (isNaN(ts.p.width)) {
					ts.p.width = grid.width = initwidth;
				} else {
					grid.width = ts.p.width;
				}
				ts.p.tblwidth = initwidth;
				if (ts.p.shrinkToFit === false && ts.p.forceFit === true) {
					ts.p.forceFit = false;
				}
				if (ts.p.shrinkToFit === true && vc > 0) {
					aw = grid.width - brd * vc - gw;
					if (isNaN(ts.p.height)) {}
					else {
						aw -= scw;
						hs = true;
					}
					initwidth = 0;
					$.each(ts.p.colModel, function (i) {
						if (this.hidden === false && !this.fixed) {
							cw = Math.round(aw * this.width / (ts.p.tblwidth - tw));
							this.width = cw;
							initwidth += cw;
							lvc = i;
						}
					});
					cr = 0;
					if (hs) {
						if (grid.width - gw - (initwidth + brd * vc) !== scw) {
							cr = grid.width - gw - (initwidth + brd * vc) - scw;
						}
					} else if (!hs && Math.abs(grid.width - gw - (initwidth + brd * vc)) !== 1) {
						cr = grid.width - gw - (initwidth + brd * vc);
					}
					ts.p.colModel[lvc].width += cr;
					ts.p.tblwidth = initwidth + cr + tw + cl * brd;
					if (ts.p.tblwidth > ts.p.width) {
						ts.p.colModel[lvc].width -= (ts.p.tblwidth - parseInt(ts.p.width, 10));
						ts.p.tblwidth = ts.p.width;
					}
				}
			},
			nextVisible = function (iCol) {
				var ret = iCol,
				j = iCol,
				i;
				for (i = iCol + 1; i < ts.p.colModel.length; i++) {
					if (ts.p.colModel[i].hidden !== true) {
						j = i;
						break;
					}
				}
				return j - ret;
			},
			getOffset = function (iCol) {
				var i,
				ret = {},
				brd1 = isSafari ? 0 : ts.p.cellLayout;
				ret[0] = ret[1] = ret[2] = 0;
				for (i = 0; i <= iCol; i++) {
					if (ts.p.colModel[i].hidden === false) {
						ret[0] += ts.p.colModel[i].width + brd1;
					}
				}
				if (ts.p.direction == "rtl") {
					ret[0] = ts.p.width - ret[0];
				}
				ret[0] = ret[0] - ts.grid.bDiv.scrollLeft;
				if ($(ts.grid.cDiv).is(":visible")) {
					ret[1] += $(ts.grid.cDiv).height() + parseInt($(ts.grid.cDiv).css("padding-top"), 10) + parseInt($(ts.grid.cDiv).css("padding-bottom"), 10);
				}
				if (ts.p.toolbar[0] === true && (ts.p.toolbar[1] == 'top' || ts.p.toolbar[1] == 'both')) {
					ret[1] += $(ts.grid.uDiv).height() + parseInt($(ts.grid.uDiv).css("border-top-width"), 10) + parseInt($(ts.grid.uDiv).css("border-bottom-width"), 10);
				}
				if (ts.p.toppager) {
					ret[1] += $(ts.grid.topDiv).height() + parseInt($(ts.grid.topDiv).css("border-bottom-width"), 10);
				}
				ret[2] += $(ts.grid.bDiv).height() + $(ts.grid.hDiv).height();
				return ret;
			};
			this.p.id = this.id;
			if ($.inArray(ts.p.multikey, sortkeys) == -1) {
				ts.p.multikey = false;
			}
			ts.p.keyIndex = false;
			for (i = 0; i < ts.p.colModel.length; i++) {
				if (ts.p.colModel[i].key === true) {
					ts.p.keyIndex = i;
					break;
				}
			}
			ts.p.sortorder = ts.p.sortorder.toLowerCase();
			if (ts.p.grouping === true) {
				ts.p.scroll = false;
				ts.p.rownumbers = false;
				ts.p.subGrid = false;
				ts.p.treeGrid = false;
				ts.p.gridview = true;
			}
			if (this.p.treeGrid === true) {
				try {
					$(this).jqGrid("setTreeGrid");
				} catch (_) {}
				if (ts.p.datatype != "local") {
					ts.p.localReader = {
						id : "_id_"
					};
				}
			}
			if (this.p.subGrid) {
				try {
					$(ts).jqGrid("setSubGrid");
				} catch (_) {}
				
			}
			if (this.p.multiselect) {
				this.p.colNames.unshift("<input role='checkbox' id='cb_" + this.p.id + "' class='cbox' type='checkbox' style='margin-top:8px'onclick='headcheckboxchange()'/>");
				this.p.colModel.unshift({
					name : 'cb',
					width : isSafari ? ts.p.multiselectWidth : ts.p.multiselectWidth,
					sortable : false,
					resizable : false,
					hidedlg : true,
					search : false,
					align : 'center',
					fixed : true
				});
			}
			if (this.p.rownumbers) {
				this.p.colNames.unshift("xxxx");
				this.p.colModel.unshift({
					name : 'rn',
					width : ts.p.rownumWidth,
					sortable : false,
					resizable : false,
					hidedlg : true,
					search : false,
					align : 'center',
					fixed : true
				});
			}
			ts.p.xmlReader = $.extend(true, {
					root : "rows",
					row : "row",
					page : "rows>page",
					total : "rows>total",
					records : "rows>records",
					repeatitems : true,
					cell : "cell",
					id : "[id]",
					userdata : "userdata",
					subgrid : {
						root : "rows",
						row : "row",
						repeatitems : true,
						cell : "cell"
					}
				}, ts.p.xmlReader);
			ts.p.jsonReader = $.extend(true, {
					root : "rows",
					page : "page",
					total : "total",
					records : "records",
					repeatitems : true,
					cell : "cell",
					id : "id",
					userdata : "userdata",
					subgrid : {
						root : "rows",
						repeatitems : true,
						cell : "cell"
					}
				}, ts.p.jsonReader);
			ts.p.localReader = $.extend(true, {
					root : "rows",
					page : "page",
					total : "total",
					records : "records",
					repeatitems : false,
					cell : "cell",
					id : "id",
					userdata : "userdata",
					subgrid : {
						root : "rows",
						repeatitems : true,
						cell : "cell"
					}
				}, ts.p.localReader);
			if (ts.p.scroll) {
				ts.p.pgbuttons = false;
				ts.p.pginput = false;
				ts.p.rowList = [];
			}
			if (ts.p.data.length) {
				refreshIndex();
			}
			var thead = "<thead><tr class='ui-jqgrid-labels' role='rowheader'>",
			tdc,
			idn,
			w,
			res,
			sort,
			td,
			ptr,
			tbody,
			imgs,
			iac = "",
			idc = "";
			if (ts.p.shrinkToFit === true && ts.p.forceFit === true) {
				for (i = ts.p.colModel.length - 1; i >= 0; i--) {
					if (!ts.p.colModel[i].hidden) {
						ts.p.colModel[i].resizable = false;
						break;
					}
				}
			}
			if (ts.p.viewsortcols[1] == 'horizontal') {
				iac = " ui-i-asc";
				idc = " ui-i-desc";
			}
			tdc = isMSIE ? "class='ui-th-div-ie'" : "";
			imgs = "<span class='s-ico' style=''><img src='" + contextPath + "/images/arrow_n.gif' style='position:absolute;bottom:9px;padding-left:2px' name='updownimg'></span>";
			for (i = 0; i < this.p.colNames.length; i++) {
				var tooltip = ts.p.headertitles ? (" title=\"" + $.jgrid.stripHtml(ts.p.colNames[i]) + "\"") : "";
				thead += "<th id='" + ts.p.id + "_" + ts.p.colModel[i].name + "' role='columnheader' class='ui-state-default ui-th-column ui-th-" + dir + "'" + tooltip + ">";
				idn = ts.p.colModel[i].index || ts.p.colModel[i].name;
				thead += "<div id='jqgh_" + ts.p.colModel[i].name + "' " + tdc + ">" + ts.p.colNames[i];
				if (!ts.p.colModel[i].width) {
					ts.p.colModel[i].width = 150;
				} else {
					ts.p.colModel[i].width = parseInt(ts.p.colModel[i].width, 10);
				}
				if (typeof(ts.p.colModel[i].title) !== "boolean") {
					ts.p.colModel[i].title = true;
				}
				if (idn == ts.p.sortname) {
					ts.p.lastsort = i;
				}
				thead += imgs + "</div></th>";
			}
			thead += "</tr></thead>";
			imgs = null;
			$(this).append(thead);
			$("thead tr:first th", this).hover(function () {
				$(this).addClass('ui-state-hove');
			}, function () {
				$(this).removeClass('ui-state-hove');
			});
			if (this.p.multiselect) {
				var emp = [],
				chk;
				$('#cb_' + $.jgrid.jqID(ts.p.id), this).bind('click', function () {
					if (this.checked) {
						$("[id^=jqg_" + ts.p.id + "_" + "]").attr("checked", "checked");
						$(ts.rows).each(function (i) {
							if (i > 0) {
								if (!$(this).hasClass("subgrid") && !$(this).hasClass("jqgroup")) {
									$(this).addClass("ui-state-highlight").attr("aria-selected", "true");
									checkboxchange();
									ts.p.selarrrow[i] = ts.p.selrow = this.id;
								}
							}
						});
						chk = true;
						emp = [];
					} else {
						$("[id^=jqg_" + ts.p.id + "_" + "]").removeAttr("checked");
						$(ts.rows).each(function (i) {
							if (!$(this).hasClass("subgrid")) {
								$(this).removeClass("ui-state-highlight").attr("aria-selected", "false");
								emp[i] = this.id;
							}
						});
						ts.p.selarrrow = [];
						ts.p.selrow = null;
						chk = false;
					}
					if ($.isFunction(ts.p.onSelectAll)) {
						ts.p.onSelectAll.call(ts, chk ? ts.p.selarrrow : emp, chk);
					}
				});
			}
			if (ts.p.autowidth === true) {
				var pw = $(eg).innerWidth();
				ts.p.width = pw > 0 ? pw : 'nw';
			}
			setColWidth();
			$(eg).css("width", grid.width + "px").append("<div class='ui-jqgrid-resize-mark' id='rs_m" + ts.p.id + "'>&#160;</div>");
			$(gv).css("width", grid.width + "px");
			thead = $("thead:first", ts).get(0);
			var tfoot = "";
			if (ts.p.footerrow) {
				tfoot += "<table role='grid' style='width:" + ts.p.tblwidth + "px' class='ui-jqgrid-ftable' cellspacing='0' cellpadding='0' border='0'><tbody><tr role='row' class='ui-widget-content footrow footrow-" + dir + "'>";
			}
			var thr = $("tr:first", thead),
			firstr = "<tr class='jqgfirstrow' role='row' style='height:auto'>";
			ts.p.disableClick = false;
			$("th", thr).each(function (j) {
				w = ts.p.colModel[j].width;
				if (typeof ts.p.colModel[j].resizable === 'undefined') {
					ts.p.colModel[j].resizable = true;
				}
				if (ts.p.colModel[j].resizable) {
					res = document.createElement("span");
					$(res).html("&#160;").addClass('ui-jqgrid-resize ui-jqgrid-resize-' + dir);
					if (!$.browser.opera) {
						$(res).css("cursor", "col-resize");
					}
					$(this).addClass(ts.p.resizeclass);
				} else {
					res = "";
				}
				$(this).css("width", w + "px").prepend(res);
				var hdcol = "";
				if (ts.p.colModel[j].hidden) {
					$(this).css("display", "none");
					hdcol = "display:none;";
				}
				firstr += "<td role='gridcell' style='height:0px;width:" + w + "px;" + hdcol + "'></td>";
				grid.headers[j] = {
					width : w,
					el : this
				};
				sort = ts.p.colModel[j].sortable;
				if (typeof sort !== 'boolean') {
					ts.p.colModel[j].sortable = true;
					sort = true;
				}
				var nm = ts.p.colModel[j].name;
				if (!(nm == 'cb' || nm == 'subgrid' || nm == 'rn')) {
					if (ts.p.viewsortcols[2]) {
						$("div", this).addClass('ui-jqgrid-sortable');
					}
				}
				if (sort) {
					if (ts.p.viewsortcols[0]) {
						$("div span.s-ico", this).show();
						if (j == ts.p.lastsort) {
							$("div span.ui-icon-" + ts.p.sortorder, this).removeClass("ui-state-disabled");
						}
					} else if (j == ts.p.lastsort) {
						$("div span.s-ico", this).show();
						$("div span.ui-icon-" + ts.p.sortorder, this).removeClass("ui-state-disabled");
					}
				} else {
					$("div span.s-ico", this).remove();
					$("div", this).removeClass('ui-jqgrid-sortable');
				}
				if (ts.p.footerrow) {
					tfoot += "<td role='gridcell' " + formatCol(j, 0, '') + ">&#160;</td>";
				}
			}).mousedown(function (e) {
				if ($(e.target).closest("th>span.ui-jqgrid-resize").length != 1) {
					return;
				}
				var ci = $.jgrid.getCellIndex(this);
				if (ts.p.forceFit === true) {
					ts.p.nv = nextVisible(ci);
				}
				grid.dragStart(ci, e, getOffset(ci));
				return false;
			}).click(function (e) {
				if (ts.p.disableClick) {
					ts.p.disableClick = false;
					return false;
				}
				var s = "th>div.ui-jqgrid-sortable",
				r,
				d;
				if (!ts.p.viewsortcols[2]) {
					s = "th>div>span>span.ui-grid-ico-sort";
				}
				var t = $(e.target).closest(s);
				if (t.length != 1) {
					return;
				}
				var ci = $.jgrid.getCellIndex(this);
				if (!ts.p.viewsortcols[2]) {
					r = true;
					d = t.attr("sort");
				}
				sortData($('div', this)[0].id, ci, r, d);
				return false;
			});
			if (ts.p.sortable && $.fn.sortable) {
				try {
					$(ts).jqGrid("sortableColumns", thr);
				} catch (e) {}
				
			}
			if (ts.p.footerrow) {
				tfoot += "</tr></tbody></table>";
			}
			firstr += "</tr>";
			tbody = document.createElement("tbody");
			this.appendChild(tbody);
			$(this).addClass('ui-jqgrid-btable').append(firstr);
			firstr = null;
			var hTable = $("<table class='ui-jqgrid-htable' style='width:" + ts.p.tblwidth + "px' role='grid' aria-labelledby='gbox_" + this.id + "' cellspacing='0' cellpadding='0' border='0'></table>").append(thead),
			hg = (ts.p.caption && ts.p.hiddengrid === true) ? true : false,
			hb = $("<div class='ui-jqgrid-hbox" + (dir == "rtl" ? "-rtl" : "") + "'></div>");
			thead = null;
			grid.hDiv = document.createElement("div");
			$(grid.hDiv).css({
				width : (grid.width + 1) + "px"
			}).addClass("ui-state-default ui-jqgrid-hdiv").append(hb);
			$(hb).append(hTable);
			hTable = null;
			if (hg) {
				$(grid.hDiv).hide();
			}
			if (ts.p.pager) {
				if (typeof ts.p.pager == "string") {
					if (ts.p.pager.substr(0, 1) != "#") {
						ts.p.pager = "#" + ts.p.pager;
					}
				} else {
					ts.p.pager = "#" + $(ts.p.pager).attr("id");
				}
				$(ts.p.pager).css({
					width : (grid.width + 2) + "px"
				}).appendTo(eg).addClass('ui-state-default ui-jqgrid-pager ui-corner-bottom');
				if (hg) {
					$(ts.p.pager).hide();
				}
				setPager(ts.p.pager, '');
			}
			if (ts.p.cellEdit === false && ts.p.hoverrows === true) {
				$(ts).bind('mouseover', function (e) {
					ptr = $(e.target).closest("tr.jqgrow");
					if ($(ptr).attr("class") !== "subgrid") {
						$(ptr).addClass("ui-state-hover");
					}
					return false;
				}).bind('mouseout', function (e) {
					ptr = $(e.target).closest("tr.jqgrow");
					$(ptr).removeClass("ui-state-hover");
					return false;
				});
			}
			var ri,
			ci;
			$(ts).before(grid.hDiv).click(function (e) {
				td = e.target;
				var scb = $(td).hasClass("cbox");
				ptr = $(td, ts.rows).closest("tr.jqgrow");
				if ($(ptr).length === 0) {
					return this;
				}
				var cSel = true;
				if ($.isFunction(ts.p.beforeSelectRow)) {
					cSel = ts.p.beforeSelectRow.call(ts, ptr[0].id, e);
				}
				if (td.tagName == 'A' || ((td.tagName == 'INPUT' || td.tagName == 'TEXTAREA' || td.tagName == 'OPTION' || td.tagName == 'SELECT') && !scb)) {
					return this;
				}
				if (cSel === true) {
					if (ts.p.cellEdit === true) {
						if (ts.p.multiselect && scb) {
							$(ts).jqGrid("setSelection", ptr[0].id, true);
						} else {
							ri = ptr[0].rowIndex;
							ci = $.jgrid.getCellIndex(td);
							try {
								$(ts).jqGrid("editCell", ri, ci, true);
							} catch (_) {}
							
						}
					} else if (!ts.p.multikey) {
						if (ts.p.multiselect && ts.p.multiboxonly) {
							if (scb) {
								$(ts).jqGrid("setSelection", ptr[0].id, true);
							} else {
								$(ts.p.selarrrow).each(function (i, n) {
									var ind = ts.rows.namedItem(n);
									$(ind).removeClass("ui-state-highlight");
									$("#jqg_" + ts.p.id + "_" + $.jgrid.jqID(n)).attr("checked", false);
								});
								ts.p.selarrrow = [];
								$("#cb_" + $.jgrid.jqID(ts.p.id), ts.grid.hDiv).attr("checked", false);
								$(ts).jqGrid("setSelection", ptr[0].id, true);
							}
						} else {
							$(ts).jqGrid("setSelection", ptr[0].id, true);
						}
					} else {
						if (e[ts.p.multikey]) {
							$(ts).jqGrid("setSelection", ptr[0].id, true);
						} else if (ts.p.multiselect && scb) {
							scb = $("[id^=jqg_" + ts.p.id + "_" + "]").attr("checked");
							$("[id^=jqg_" + ts.p.id + "_" + "]").attr("checked", !scb);
						}
					}
					if ($.isFunction(ts.p.onCellSelect)) {
						ri = ptr[0].id;
						ci = $.jgrid.getCellIndex(td);
						ts.p.onCellSelect.call(ts, ri, ci, $(td).html(), e);
					}
					e.stopPropagation();
				} else {
					return this;
				}
			}).bind('reloadGrid', function (e, opts) {
				if (ts.p.treeGrid === true) {
					ts.p.datatype = ts.p.treedatatype;
				}
				if (opts && opts.current) {
					ts.grid.selectionPreserver(ts);
				}
				if (ts.p.datatype == "local") {
					$(ts).jqGrid("resetSelection");
					if (ts.p.data.length) {
						refreshIndex();
					}
				} else if (!ts.p.treeGrid) {
					ts.p.selrow = null;
					if (ts.p.multiselect) {
						ts.p.selarrrow = [];
						$('#cb_' + $.jgrid.jqID(ts.p.id), ts.grid.hDiv).attr("checked", false);
					}
					ts.p.savedRow = [];
				}
				if (ts.p.scroll) {
					emptyRows(ts.grid.bDiv, true);
				}
				if (opts && opts.page) {
					var page = opts.page;
					if (page > ts.p.lastpage) {
						page = ts.p.lastpage;
					}
					if (page < 1) {
						page = 1;
					}
					ts.p.page = page;
					if (ts.grid.prevRowHeight) {
						ts.grid.bDiv.scrollTop = (page - 1) * ts.grid.prevRowHeight * ts.p.rowNum;
					} else {
						ts.grid.bDiv.scrollTop = 0;
					}
				}
				if (ts.grid.prevRowHeight && ts.p.scroll) {
					delete ts.p.lastpage;
					ts.grid.populateVisible();
				} else {
					ts.grid.populate();
				}
				return false;
			});
			if ($.isFunction(this.p.ondblClickRow)) {
				$(this).dblclick(function (e) {
					td = e.target;
					ptr = $(td, ts.rows).closest("tr.jqgrow");
					if ($(ptr).length === 0) {
						return false;
					}
					ri = ptr[0].rowIndex;
					ci = $.jgrid.getCellIndex(td);
					ts.p.ondblClickRow.call(ts, $(ptr).attr("id"), ri, ci, e);
					return false;
				});
			}
			if ($.isFunction(this.p.onRightClickRow)) {
				$(this).bind('contextmenu', function (e) {
					td = e.target;
					ptr = $(td, ts.rows).closest("tr.jqgrow");
					if ($(ptr).length === 0) {
						return false;
					}
					if (!ts.p.multiselect) {
						$(ts).jqGrid("setSelection", ptr[0].id, true);
					}
					ri = ptr[0].rowIndex;
					ci = $.jgrid.getCellIndex(td);
					ts.p.onRightClickRow.call(ts, $(ptr).attr("id"), ri, ci, e);
					return false;
				});
			}
			grid.bDiv = document.createElement("div");
			$(grid.bDiv).append($('<div style="position:relative;' + (isMSIE && $.browser.version < 8 ? "height:0.01%;" : "") + '"></div>').append('<div></div>').append(this)).addClass("ui-jqgrid-bdiv").css({
				height : ts.p.height + (isNaN(ts.p.height) ? "" : "px"),
				width : (grid.width) + "px"
			}).scroll(grid.scrollGrid);
			$("table:first", grid.bDiv).css({
				width : ts.p.tblwidth + "px"
			});
			if (isMSIE) {
				if ($("tbody", this).size() == 2) {
					$("tbody:gt(0)", this).remove();
				}
				if (ts.p.multikey) {
					$(grid.bDiv).bind("selectstart", function () {
						return false;
					});
				}
			} else {
				if (ts.p.multikey) {
					$(grid.bDiv).bind("mousedown", function () {
						return false;
					});
				}
			}
			if (hg) {
				$(grid.bDiv).hide();
			}
			grid.cDiv = document.createElement("div");
			var arf = ts.p.hidegrid === true ? $("<a role='link' href='javascript:void(0)'/>").addClass('ui-jqgrid-titlebar-close HeaderButton').hover(function () {
					arf.addClass('ui-state-hover');
				}, function () {
					arf.removeClass('ui-state-hover');
				}).append("<span class='ui-icon ui-icon-circle-triangle-n'></span>").css((dir == "rtl" ? "left" : "right"), "0px") : "";
			$(grid.cDiv).append(arf).append("<span class='ui-jqgrid-title" + (dir == "rtl" ? "-rtl" : "") + "'>" + ts.p.caption + "</span>").addClass("ui-jqgrid-titlebar ui-widget-header ui-corner-top ui-helper-clearfix");
			$(grid.cDiv).insertBefore(grid.hDiv);
			if (ts.p.toolbar[0]) {
				grid.uDiv = document.createElement("div");
				if (ts.p.toolbar[1] == "top") {
					$(grid.uDiv).insertBefore(grid.hDiv);
				} else if (ts.p.toolbar[1] == "bottom") {
					$(grid.uDiv).insertAfter(grid.hDiv);
				}
				if (ts.p.toolbar[1] == "both") {
					grid.ubDiv = document.createElement("div");
					$(grid.uDiv).insertBefore(grid.hDiv).addClass("ui-userdata ui-state-default").attr("id", "t_" + this.id);
					$(grid.ubDiv).insertAfter(grid.hDiv).addClass("ui-userdata ui-state-default").attr("id", "tb_" + this.id);
					if (hg) {
						$(grid.ubDiv).hide();
					}
				} else {
					$(grid.uDiv).width(grid.width).addClass("ui-userdata ui-state-default").attr("id", "t_" + this.id);
				}
				if (hg) {
					$(grid.uDiv).hide();
				}
			}
			if (ts.p.toppager) {
				ts.p.toppager = ts.p.id + "_toppager";
				grid.topDiv = $("<div id='" + ts.p.toppager + "'></div>")[0];
				ts.p.toppager = "#" + ts.p.toppager;
				$(grid.topDiv).insertBefore(grid.hDiv).addClass('ui-state-default ui-jqgrid-toppager').width(grid.width);
				setPager(ts.p.toppager, '_t');
			}
			if (ts.p.footerrow) {
				grid.sDiv = $("<div class='ui-jqgrid-sdiv'></div>")[0];
				hb = $("<div class='ui-jqgrid-hbox" + (dir == "rtl" ? "-rtl" : "") + "'></div>");
				$(grid.sDiv).append(hb).insertAfter(grid.hDiv).width(grid.width);
				$(hb).append(tfoot);
				grid.footers = $(".ui-jqgrid-ftable", grid.sDiv)[0].rows[0].cells;
				if (ts.p.rownumbers) {
					grid.footers[0].className = 'ui-state-default jqgrid-rownum';
				}
				if (hg) {
					$(grid.sDiv).hide();
				}
			}
			hb = null;
			if (ts.p.caption) {
				var tdt = ts.p.datatype;
				if (ts.p.hidegrid === true) {
					$(".ui-jqgrid-titlebar-close", grid.cDiv).click(function (e) {
						var onHdCl = $.isFunction(ts.p.onHeaderClick);
						if (ts.p.gridstate == 'visible') {
							$(".ui-jqgrid-bdiv, .ui-jqgrid-hdiv", "#gview_" + ts.p.id).slideUp("fast");
							if (ts.p.pager) {
								$(ts.p.pager).slideUp("fast");
							}
							if (ts.p.toppager) {
								$(ts.p.toppager).slideUp("fast");
							}
							if (ts.p.toolbar[0] === true) {
								if (ts.p.toolbar[1] == 'both') {
									$(grid.ubDiv).slideUp("fast");
								}
								$(grid.uDiv).slideUp("fast");
							}
							if (ts.p.footerrow) {
								$(".ui-jqgrid-sdiv", "#gbox_" + ts.p.id).slideUp("fast");
							}
							$("span", this).removeClass("ui-icon-circle-triangle-n").addClass("ui-icon-circle-triangle-s");
							ts.p.gridstate = 'hidden';
							if ($("#gbox_" + ts.p.id).hasClass("ui-resizable")) {
								$(".ui-resizable-handle", "#gbox_" + ts.p.id).hide();
							}
							if (onHdCl) {
								if (!hg) {
									ts.p.onHeaderClick.call(ts, ts.p.gridstate, e);
								}
							}
						} else if (ts.p.gridstate == 'hidden') {
							$(".ui-jqgrid-hdiv, .ui-jqgrid-bdiv", "#gview_" + ts.p.id).slideDown("fast");
							if (ts.p.pager) {
								$(ts.p.pager).slideDown("fast");
							}
							if (ts.p.toppager) {
								$(ts.p.toppager).slideDown("fast");
							}
							if (ts.p.toolbar[0] === true) {
								if (ts.p.toolbar[1] == 'both') {
									$(grid.ubDiv).slideDown("fast");
								}
								$(grid.uDiv).slideDown("fast");
							}
							if (ts.p.footerrow) {
								$(".ui-jqgrid-sdiv", "#gbox_" + ts.p.id).slideDown("fast");
							}
							$("span", this).removeClass("ui-icon-circle-triangle-s").addClass("ui-icon-circle-triangle-n");
							if (hg) {
								ts.p.datatype = tdt;
								populate();
								hg = false;
							}
							ts.p.gridstate = 'visible';
							if ($("#gbox_" + ts.p.id).hasClass("ui-resizable")) {
								$(".ui-resizable-handle", "#gbox_" + ts.p.id).show();
							}
							if (onHdCl) {
								ts.p.onHeaderClick.call(ts, ts.p.gridstate, e);
							}
						}
						return false;
					});
					if (hg) {
						ts.p.datatype = "local";
						$(".ui-jqgrid-titlebar-close", grid.cDiv).trigger("click");
					}
				}
			} else {
				$(grid.cDiv).hide();
			}
			$(grid.hDiv).after(grid.bDiv).mousemove(function (e) {
				if (grid.resizing) {
					grid.dragMove(e);
					return false;
				}
			});
			$(".ui-jqgrid-labels", grid.hDiv).bind("selectstart", function () {
				return false;
			});
			$(document).mouseup(function (e) {
				if (grid.resizing) {
					grid.dragEnd();
					return false;
				}
				return true;
			});
			ts.formatCol = formatCol;
			ts.sortData = sortData;
			ts.updatepager = updatepager;
			ts.refreshIndex = refreshIndex;
			ts.formatter = function (rowId, cellval, colpos, rwdat, act) {
				return formatter(rowId, cellval, colpos, rwdat, act);
			};
			$.extend(grid, {
				populate : populate,
				emptyRows : emptyRows
			});
			this.grid = grid;
			ts.addXmlData = function (d) {
				addXmlData(d, ts.grid.bDiv);
			};
			ts.addJSONData = function (d) {
				addJSONData(d, ts.grid.bDiv);
			};
			this.grid.cols = this.rows[0].cells;
			populate();
			ts.p.hiddengrid = false;
			$(window).unload(function () {
				ts = null;
			});
		});
	};
	$.jgrid.extend({
		getGridParam : function (pName) {
			var $t = this[0];
			if (!$t || !$t.grid) {
				return;
			}
			if (!pName) {
				return $t.p;
			} else {
				return typeof($t.p[pName]) != "undefined" ? $t.p[pName] : null;
			}
		},
		setGridParam : function (newParams) {
			return this.each(function () {
				if (this.grid && typeof(newParams) === 'object') {
					$.extend(true, this.p, newParams);
				}
			});
		},
		getDataIDs : function () {
			var ids = [],
			i = 0,
			len,
			j = 0;
			this.each(function () {
				len = this.rows.length;
				if (len && len > 0) {
					while (i < len) {
						if ($(this.rows[i]).hasClass('jqgrow')) {
							ids[j] = this.rows[i].id;
							j++;
						}
						i++;
					}
				}
			});
			return ids;
		},
		setSelection : function (selection, onsr) {
			return this.each(function () {
				var $t = this,
				stat,
				pt,
				ner,
				ia,
				tpsr;
				if (selection === undefined) {
					return;
				}
				onsr = onsr === false ? false : true;
				pt = $t.rows.namedItem(selection + "");
				if (!pt) {
					return;
				}
				function scrGrid(iR) {
					var ch = $($t.grid.bDiv)[0].clientHeight,
					st = $($t.grid.bDiv)[0].scrollTop,
					rpos = $t.rows[iR].offsetTop,
					rh = $t.rows[iR].clientHeight;
					if (rpos + rh >= ch + st) {
						$($t.grid.bDiv)[0].scrollTop = rpos - (ch + st) + rh + st;
					} else if (rpos < ch + st) {
						if (rpos < st) {
							$($t.grid.bDiv)[0].scrollTop = rpos;
						}
					}
				}
				if ($t.p.scrollrows === true) {
					ner = $t.rows.namedItem(selection).rowIndex;
					if (ner >= 0) {
						scrGrid(ner);
					}
				}
				if (!$t.p.multiselect) {
					if (pt.className !== "ui-subgrid") {
						if ($t.p.selrow) {
							$($t.rows.namedItem($t.p.selrow)).removeClass("ui-state-highlight").attr("aria-selected", "false");
						}
						$t.p.selrow = pt.id;
						if ($t.p.onSelectRow && onsr) {
							$t.p.onSelectRow.call($t, $t.p.selrow, true);
						}
					}
				} else {
					$t.p.selrow = pt.id;
					ia = $.inArray($t.p.selrow, $t.p.selarrrow);
					if (ia === -1) {
						if (pt.className !== "ui-subgrid") {
							$(pt).addClass("ui-state-highlight").attr("aria-selected", "true");
						}
						stat = true;
						$("#jqg_" + $t.p.id + "_" + $.jgrid.jqID($t.p.selrow)).attr("checked", stat);
						$t.p.selarrrow.push($t.p.selrow);
						if ($t.p.onSelectRow && onsr) {
							$t.p.onSelectRow.call($t, $t.p.selrow, stat);
						}
						checkboxchange();
					} else {
						if (pt.className !== "ui-subgrid") {
							$(pt).removeClass("ui-state-highlight").attr("aria-selected", "false");
						}
						stat = false;
						$("#jqg_" + $t.p.id + "_" + $.jgrid.jqID($t.p.selrow)).attr("checked", stat);
						$t.p.selarrrow.splice(ia, 1);
						if ($t.p.onSelectRow && onsr) {
							$t.p.onSelectRow.call($t, $t.p.selrow, stat);
						}
						tpsr = $t.p.selarrrow[0];
						$t.p.selrow = (tpsr === undefined) ? null : tpsr;
						checkboxchange();
					}
				}
			});
		},
		resetSelection : function () {
			return this.each(function () {
				var t = this,
				ind;
				if (!t.p.multiselect) {
					if (t.p.selrow) {
						$("#" + t.p.id + " tbody:first tr#" + $.jgrid.jqID(t.p.selrow)).removeClass("ui-state-highlight").attr("aria-selected", "false");
						t.p.selrow = null;
					}
				} else {
					$(t.p.selarrrow).each(function (i, n) {
						ind = t.rows.namedItem(n);
						$(ind).removeClass("ui-state-highlight").attr("aria-selected", "false");
						$("#jqg_" + t.p.id + "_" + $.jgrid.jqID(n)).attr("checked", false);
					});
					$("#cb_" + $.jgrid.jqID(t.p.id)).attr("checked", false);
					t.p.selarrrow = [];
				}
				t.p.savedRow = [];
			});
		},
		getRowData : function (rowid) {
			var res = {},
			resall,
			getall = false,
			len,
			j = 0;
			this.each(function () {
				var $t = this,
				nm,
				ind;
				if (typeof(rowid) == 'undefined') {
					getall = true;
					resall = [];
					len = $t.rows.length;
				} else {
					ind = $t.rows.namedItem(rowid);
					if (!ind) {
						return res;
					}
					len = 2;
				}
				while (j < len) {
					if (getall) {
						ind = $t.rows[j];
					}
					if ($(ind).hasClass('jqgrow')) {
						$('td', ind).each(function (i) {
							nm = $t.p.colModel[i].name;
							if (nm !== 'cb' && nm !== 'subgrid' && nm !== 'rn') {
								if ($t.p.treeGrid === true && nm == $t.p.ExpandColumn) {
									res[nm] = $.jgrid.htmlDecode($("span:first", this).html());
								} else {
									try {
										res[nm] = $.unformat(this, {
												rowId : ind.id,
												colModel : $t.p.colModel[i]
											}, i);
									} catch (e) {
										res[nm] = $.jgrid.htmlDecode($(this).html());
									}
								}
							}
						});
						if (getall) {
							resall.push(res);
							res = {};
						}
					}
					j++;
				}
			});
			return resall ? resall : res;
		},
		delRowData : function (rowid) {
			var success = false,
			rowInd,
			ia,
			ri;
			this.each(function () {
				var $t = this;
				rowInd = $t.rows.namedItem(rowid);
				if (!rowInd) {
					return false;
				} else {
					ri = rowInd.rowIndex;
					$(rowInd).remove();
					$t.p.records--;
					$t.p.reccount--;
					$t.updatepager(true, false);
					success = true;
					if ($t.p.multiselect) {
						ia = $.inArray(rowid, $t.p.selarrrow);
						if (ia != -1) {
							$t.p.selarrrow.splice(ia, 1);
						}
					}
					if (rowid == $t.p.selrow) {
						$t.p.selrow = null;
					}
				}
				if ($t.p.datatype == 'local') {
					var pos = $t.p._index[rowid];
					if (typeof(pos) != 'undefined') {
						$t.p.data.splice(pos, 1);
						$t.refreshIndex();
					}
				}
				if ($t.p.altRows === true && success) {
					var cn = $t.p.altclass;
					$($t.rows).each(function (i) {
						if (i % 2 == 1) {
							$(this).addClass(cn);
						} else {
							$(this).removeClass(cn);
						}
					});
				}
			});
			return success;
		},
		setRowData : function (rowid, data, cssp) {
			var nm,
			success = true,
			title;
			this.each(function () {
				if (!this.grid) {
					return false;
				}
				var t = this,
				vl,
				ind,
				cp = typeof cssp,
				lcdata = {};
				ind = t.rows.namedItem(rowid);
				if (!ind) {
					return false;
				}
				if (data) {
					try {
						$(this.p.colModel).each(function (i) {
							nm = this.name;
							if (data[nm] !== undefined) {
								lcdata[nm] = this.formatter && typeof(this.formatter) === 'string' && this.formatter == 'date' ? $.unformat.date(data[nm], this) : data[nm];
								vl = t.formatter(rowid, data[nm], i, data, 'edit');
								title = this.title ? {
									"title" : $.jgrid.stripHtml(vl)
								}
								 : {};
								if (t.p.treeGrid === true && nm == t.p.ExpandColumn) {
									$("td:eq(" + i + ") > span:first", ind).html(vl).attr(title);
								} else {
									$("td:eq(" + i + ")", ind).html(vl).attr(title);
								}
							}
						});
						if (t.p.datatype == 'local') {
							var pos = t.p._index[rowid];
							if (typeof(pos) != 'undefined') {
								t.p.data[pos] = $.extend(true, t.p.data[pos], lcdata);
							}
							lcdata = null;
						}
					} catch (e) {
						success = false;
					}
				}
				if (success) {
					if (cp === 'string') {
						$(ind).addClass(cssp);
					} else if (cp === 'object') {
						$(ind).css(cssp);
					}
				}
			});
			return success;
		},
		addRowData : function (rowid, rdata, pos, src) {
			if (!pos) {
				pos = "last";
			}
			var success = false,
			nm,
			row,
			gi,
			si,
			ni,
			sind,
			i,
			v,
			prp = "",
			aradd,
			cnm,
			cn,
			data,
			cm;
			if (rdata) {
				if ($.isArray(rdata)) {
					aradd = true;
					pos = "last";
					cnm = rowid;
				} else {
					rdata = [rdata];
					aradd = false;
				}
				this.each(function () {
					var t = this,
					datalen = rdata.length;
					ni = t.p.rownumbers === true ? 1 : 0;
					gi = t.p.multiselect === true ? 1 : 0;
					si = t.p.subGrid === true ? 1 : 0;
					if (!aradd) {
						if (typeof(rowid) != 'undefined') {
							rowid = rowid + "";
						} else {
							rowid = (t.p.records + 1) + "";
							if (t.p.keyIndex !== false) {
								cnm = t.p.colModel[t.p.keyIndex + gi + si + ni].name;
								if (typeof rdata[0][cnm] != "undefined") {
									rowid = rdata[0][cnm];
								}
							}
						}
					}
					cn = t.p.altclass;
					var k = 0,
					cna = "",
					lcdata = {},
					air = $.isFunction(t.p.afterInsertRow) ? true : false;
					while (k < datalen) {
						data = rdata[k];
						row = "";
						if (aradd) {
							try {
								rowid = data[cnm];
							} catch (e) {
								rowid = (t.p.records + 1) + "";
							}
							cna = t.p.altRows === true ? (t.rows.length - 1) % 2 === 0 ? cn : "" : "";
						}
						if (ni) {
							prp = t.formatCol(0, 1, '');
							row += "<td role=\"gridcell\" aria-describedby=\"" + t.p.id + "_rn\" class=\"ui-state-default jqgrid-rownum\" " + prp + ">0</td>";
						}
						if (gi) {
							v = "<input role=\"checkbox\" type=\"checkbox\"" + " id=\"jqg_" + t.p.id + "_" + rowid + "\" class=\"cbox\"/>";
							prp = t.formatCol(ni, 1, '');
							row += "<td role=\"gridcell\" aria-describedby=\"" + t.p.id + "_cb\" " + prp + ">" + v + "</td>";
						}
						if (si) {
							row += $(t).jqGrid("addSubGridCell", gi + ni, 1);
						}
						for (i = gi + si + ni; i < t.p.colModel.length; i++) {
							cm = t.p.colModel[i];
							nm = cm.name;
							lcdata[nm] = cm.formatter && typeof(cm.formatter) === 'string' && cm.formatter == 'date' ? $.unformat.date(data[nm], cm) : data[nm];
							v = t.formatter(rowid, $.jgrid.getAccessor(data, nm), i, data, 'edit');
							prp = t.formatCol(i, 1, v);
							row += "<td role=\"gridcell\" aria-describedby=\"" + t.p.id + "_" + nm + "\" " + prp + ">" + v + "</td>";
						}
						row = "<tr id=\"" + rowid + "\" role=\"row\" class=\"ui-widget-content jqgrow ui-row-" + t.p.direction + " " + cna + "\">" + row + "</tr>";
						if (t.p.subGrid === true) {
							row = $(row)[0];
							$(t).jqGrid("addSubGrid", row, gi + ni);
						}
						if (t.rows.length === 0) {
							$("table:first", t.grid.bDiv).append(row);
						} else {
							switch (pos) {
							case 'last':
								$(t.rows[t.rows.length - 1]).after(row);
								break;
							case 'first':
								$(t.rows[0]).after(row);
								break;
							case 'after':
								sind = t.rows.namedItem(src);
								if (sind) {
									if ($(t.rows[sind.rowIndex + 1]).hasClass("ui-subgrid")) {
										$(t.rows[sind.rowIndex + 1]).after(row);
									} else {
										$(sind).after(row);
									}
								}
								break;
							case 'before':
								sind = t.rows.namedItem(src);
								if (sind) {
									$(sind).before(row);
									sind = sind.rowIndex;
								}
								break;
							}
						}
						t.p.records++;
						t.p.reccount++;
						if (air) {
							t.p.afterInsertRow.call(t, rowid, data, data);
						}
						k++;
						if (t.p.datatype == 'local') {
							t.p._index[rowid] = t.p.data.length;
							t.p.data.push(lcdata);
							lcdata = {};
						}
					}
					if (t.p.altRows === true && !aradd) {
						if (pos == "last") {
							if ((t.rows.length - 1) % 2 == 1) {
								$(t.rows[t.rows.length - 1]).addClass(cn);
							}
						} else {
							$(t.rows).each(function (i) {
								if (i % 2 == 1) {
									$(this).addClass(cn);
								} else {
									$(this).removeClass(cn);
								}
							});
						}
					}
					t.updatepager(true, true);
					success = true;
				});
			}
			return success;
		},
		footerData : function (action, data, format) {
			var nm,
			success = false,
			res = {},
			title;
			function isEmpty(obj) {
				for (var i in obj) {
					if (obj.hasOwnProperty(i)) {
						return false;
					}
				}
				return true;
			}
			if (typeof(action) == "undefined") {
				action = "get";
			}
			if (typeof(format) != "boolean") {
				format = true;
			}
			action = action.toLowerCase();
			this.each(function () {
				var t = this,
				vl;
				if (!t.grid || !t.p.footerrow) {
					return false;
				}
				if (action == "set") {
					if (isEmpty(data)) {
						return false;
					}
				}
				success = true;
				$(this.p.colModel).each(function (i) {
					nm = this.name;
					if (action == "set") {
						if (data[nm] !== undefined) {
							vl = format ? t.formatter("", data[nm], i, data, 'edit') : data[nm];
							title = this.title ? {
								"title" : $.jgrid.stripHtml(vl)
							}
							 : {};
							$("tr.footrow td:eq(" + i + ")", t.grid.sDiv).html(vl).attr(title);
							success = true;
						}
					} else if (action == "get") {
						res[nm] = $("tr.footrow td:eq(" + i + ")", t.grid.sDiv).html();
					}
				});
			});
			return action == "get" ? res : success;
		},
		ShowHideCol : function (colname, show) {
			return this.each(function () {
				var $t = this,
				fndh = false;
				if (!$t.grid) {
					return;
				}
				if (typeof colname === 'string') {
					colname = [colname];
				}
				show = show != "none" ? "" : "none";
				var sw = show === "" ? true : false;
				$(this.p.colModel).each(function (i) {
					if ($.inArray(this.name, colname) !== -1 && this.hidden === sw) {
						$("tr", $t.grid.hDiv).each(function () {
							$("th:eq(" + i + ")", this).css("display", show);
						});
						$($t.rows).each(function (j) {
							$("td:eq(" + i + ")", $t.rows[j]).css("display", show);
						});
						if ($t.p.footerrow) {
							$("td:eq(" + i + ")", $t.grid.sDiv).css("display", show);
						}
						if (show == "none") {
							$t.p.tblwidth -= this.width + $t.p.cellLayout;
						} else {
							$t.p.tblwidth += this.width;
						}
						this.hidden = !sw;
						fndh = true;
					}
				});
				if (fndh === true) {
					$("table:first", $t.grid.hDiv).width($t.p.tblwidth);
					$("table:first", $t.grid.bDiv).width($t.p.tblwidth);
					$t.grid.hDiv.scrollLeft = $t.grid.bDiv.scrollLeft;
					if ($t.p.footerrow) {
						$("table:first", $t.grid.sDiv).width($t.p.tblwidth);
						$t.grid.sDiv.scrollLeft = $t.grid.bDiv.scrollLeft;
					}
					if ($t.p.shrinkToFit === true) {
						$($t).jqGrid("setGridWidth", $t.grid.width - 0.001, true);
					}
				}
			});
		},
		hideCol : function (colname) {
			return this.each(function () {
				$(this).jqGrid("ShowHideCol", colname, "none");
			});
		},
		showCol : function (colname) {
			return this.each(function () {
				$(this).jqGrid("ShowHideCol", colname, "");
			});
		},
		remapColumns : function (permutation, updateCells, keepHeader) {
			function resortArray(a) {
				var ac;
				if (a.length) {
					ac = $.makeArray(a);
				} else {
					ac = $.extend({}, a);
				}
				$.each(permutation, function (i) {
					a[i] = ac[this];
				});
			}
			var ts = this.get(0);
			function resortRows(parent, clobj) {
				$(">tr" + (clobj || ""), parent).each(function () {
					var row = this;
					var elems = $.makeArray(row.cells);
					$.each(permutation, function () {
						var e = elems[this];
						if (e) {
							row.appendChild(e);
						}
					});
				});
			}
			resortArray(ts.p.colModel);
			resortArray(ts.p.colNames);
			resortArray(ts.grid.headers);
			resortRows($("thead:first", ts.grid.hDiv), keepHeader && ":not(.ui-jqgrid-labels)");
			if (updateCells) {
				resortRows($("#" + ts.p.id + " tbody:first"), ".jqgfirstrow, tr.jqgrow, tr.jqfoot");
			}
			if (ts.p.footerrow) {
				resortRows($("tbody:first", ts.grid.sDiv));
			}
			if (ts.p.remapColumns) {
				if (!ts.p.remapColumns.length) {
					ts.p.remapColumns = $.makeArray(permutation);
				} else {
					resortArray(ts.p.remapColumns);
				}
			}
			ts.p.lastsort = $.inArray(ts.p.lastsort, permutation);
			if (ts.p.treeGrid) {
				ts.p.expColInd = $.inArray(ts.p.expColInd, permutation);
			}
		},
		setGridWidth : function (nwidth, shrink) {
			return this.each(function () {
				if (!this.grid) {
					return;
				}
				var $t = this,
				cw,
				initwidth = 0,
				brd = $t.p.cellLayout,
				lvc,
				vc = 0,
				hs = false,
				scw = $t.p.scrollOffset,
				aw,
				gw = 0,
				tw = 0,
				cl = 0,
				cr;
				if (typeof shrink != 'boolean') {
					shrink = $t.p.shrinkToFit;
				}
				if (isNaN(nwidth)) {
					return;
				} else {
					nwidth = parseInt(nwidth, 10);
					$t.grid.width = $t.p.width = nwidth;
				}
				$("#gbox_" + $t.p.id).css("width", nwidth + "px");
				$("#gview_" + $t.p.id).css("width", nwidth + "px");
				$($t.grid.bDiv).css("width", nwidth + "px");
				$($t.grid.hDiv).css("width", nwidth + "px");
				if ($t.p.pager) {
					$($t.p.pager).css("width", nwidth + "px");
				}
				if ($t.p.toppager) {
					$($t.p.toppager).css("width", nwidth + "px");
				}
				if ($t.p.toolbar[0] === true) {
					$($t.grid.uDiv).css("width", nwidth + "px");
					if ($t.p.toolbar[1] == "both") {
						$($t.grid.ubDiv).css("width", nwidth + "px");
					}
				}
				if ($t.p.footerrow) {
					$($t.grid.sDiv).css("width", nwidth + "px");
				}
				if (shrink === false && $t.p.forceFit === true) {
					$t.p.forceFit = false;
				}
				if (shrink === true) {
					if ($.browser.safari) {
						brd = 0;
					}
					$.each($t.p.colModel, function (i) {
						if (this.hidden === false) {
							initwidth += parseInt(this.width, 10);
							if (this.fixed) {
								tw += this.width;
								gw += this.width + brd;
							} else {
								vc++;
							}
							cl++;
						}
					});
					if (vc === 0) {
						return;
					}
					$t.p.tblwidth = initwidth;
					aw = nwidth - brd * vc - gw;
					if (!isNaN($t.p.height)) {
						if ($($t.grid.bDiv)[0].clientHeight < $($t.grid.bDiv)[0].scrollHeight || $t.rows.length === 1) {
							hs = true;
							aw -= scw;
						}
					}
					initwidth = 0;
					var cle = $t.grid.cols.length > 0;
					$.each($t.p.colModel, function (i) {
						if (this.hidden === false && !this.fixed) {
							cw = Math.round(aw * this.width / ($t.p.tblwidth - tw));
							if (cw < 0) {
								return;
							}
							this.width = cw;
							initwidth += cw;
							$t.grid.headers[i].width = cw;
							$t.grid.headers[i].el.style.width = cw + "px";
							if ($t.p.footerrow) {
								$t.grid.footers[i].style.width = cw + "px";
							}
							if (cle) {
								$t.grid.cols[i].style.width = cw + "px";
							}
							lvc = i;
						}
					});
					cr = 0;
					if (hs) {
						if (nwidth - gw - (initwidth + brd * vc) !== scw) {
							cr = nwidth - gw - (initwidth + brd * vc) - scw;
						}
					} else if (Math.abs(nwidth - gw - (initwidth + brd * vc)) !== 1) {
						cr = nwidth - gw - (initwidth + brd * vc);
					}
					$t.p.colModel[lvc].width += cr;
					$t.p.tblwidth = initwidth + cr + tw + brd * cl;
					if ($t.p.tblwidth > nwidth) {
						var delta = $t.p.tblwidth - parseInt(nwidth, 10);
						$t.p.tblwidth = nwidth;
						cw = $t.p.colModel[lvc].width = $t.p.colModel[lvc].width - delta;
					} else {
						cw = $t.p.colModel[lvc].width;
					}
					$t.grid.headers[lvc].width = cw;
					$t.grid.headers[lvc].el.style.width = cw + "px";
					if (cle) {
						$t.grid.cols[lvc].style.width = cw + "px";
					}
					$('table:first', $t.grid.bDiv).css("width", $t.p.tblwidth + "px");
					$('table:first', $t.grid.hDiv).css("width", $t.p.tblwidth + "px");
					$t.grid.hDiv.scrollLeft = $t.grid.bDiv.scrollLeft;
					if ($t.p.footerrow) {
						$t.grid.footers[lvc].style.width = cw + "px";
						$('table:first', $t.grid.sDiv).css("width", $t.p.tblwidth + "px");
					}
				}
			});
		},
		setGridHeight : function (nh) {
			return this.each(function () {
				var $t = this;
				if (!$t.grid) {
					return;
				}
				$($t.grid.bDiv).css({
					height : nh + (isNaN(nh) ? "" : "px")
				});
				$t.p.height = nh;
				if ($t.p.scroll) {
					$t.grid.populateVisible();
				}
			});
		},
		setCaption : function (newcap) {
			return this.each(function () {
				this.p.caption = newcap;
				$("span.ui-jqgrid-title", this.grid.cDiv).html(newcap);
				$(this.grid.cDiv).show();
			});
		},
		setLabel : function (colname, nData, prop, attrp) {
			return this.each(function () {
				var $t = this,
				pos = -1;
				if (!$t.grid) {
					return;
				}
				if (isNaN(colname)) {
					$($t.p.colModel).each(function (i) {
						if (this.name == colname) {
							pos = i;
							return false;
						}
					});
				} else {
					pos = parseInt(colname, 10);
				}
				if (pos >= 0) {
					var thecol = $("tr.ui-jqgrid-labels th:eq(" + pos + ")", $t.grid.hDiv);
					if (nData) {
						var ico = $(".s-ico", thecol);
						$("[id^=jqgh_]", thecol).empty().html(nData).append(ico);
						$t.p.colNames[pos] = nData;
					}
					if (prop) {
						if (typeof prop === 'string') {
							$(thecol).addClass(prop);
						} else {
							$(thecol).css(prop);
						}
					}
					if (typeof attrp === 'object') {
						$(thecol).attr(attrp);
					}
				}
			});
		},
		setCell : function (rowid, colname, nData, cssp, attrp, forceupd) {
			return this.each(function () {
				var $t = this,
				pos = -1,
				v,
				title;
				if (!$t.grid) {
					return;
				}
				if (isNaN(colname)) {
					$($t.p.colModel).each(function (i) {
						if (this.name == colname) {
							pos = i;
							return false;
						}
					});
				} else {
					pos = parseInt(colname, 10);
				}
				if (pos >= 0) {
					var ind = $t.rows.namedItem(rowid);
					if (ind) {
						var tcell = $("td:eq(" + pos + ")", ind);
						if (nData !== "" || forceupd === true) {
							v = $t.formatter(rowid, nData, pos, ind, 'edit');
							title = $t.p.colModel[pos].title ? {
								"title" : $.jgrid.stripHtml(v)
							}
							 : {};
							if ($t.p.treeGrid && $(".tree-wrap", $(tcell)).length > 0) {
								$("span", $(tcell)).html(v).attr(title);
							} else {
								$(tcell).html(v).attr(title);
							}
							if ($t.p.datatype == "local") {
								var cm = $t.p.colModel[pos],
								index;
								nData = cm.formatter && typeof(cm.formatter) === 'string' && cm.formatter == 'date' ? $.unformat.date(nData, cm) : nData;
								index = $t.p._index[rowid];
								if (typeof index != "undefined") {
									$t.p.data[index][cm.name] = nData;
								}
							}
						}
						if (typeof cssp === 'string') {
							$(tcell).addClass(cssp);
						} else if (cssp) {
							$(tcell).css(cssp);
						}
						if (typeof attrp === 'object') {
							$(tcell).attr(attrp);
						}
					}
				}
			});
		},
		getCell : function (rowid, col) {
			var ret = false;
			this.each(function () {
				var $t = this,
				pos = -1;
				if (!$t.grid) {
					return;
				}
				if (isNaN(col)) {
					$($t.p.colModel).each(function (i) {
						if (this.name === col) {
							pos = i;
							return false;
						}
					});
				} else {
					pos = parseInt(col, 10);
				}
				if (pos >= 0) {
					var ind = $t.rows.namedItem(rowid);
					if (ind) {
						try {
							ret = $.unformat($("td:eq(" + pos + ")", ind), {
									rowId : ind.id,
									colModel : $t.p.colModel[pos]
								}, pos);
						} catch (e) {
							ret = $.jgrid.htmlDecode($("td:eq(" + pos + ")", ind).html());
						}
					}
				}
			});
			return ret;
		},
		getCol : function (col, obj, mathopr) {
			var ret = [],
			val,
			sum = 0;
			obj = typeof(obj) != 'boolean' ? false : obj;
			if (typeof mathopr == 'undefined') {
				mathopr = false;
			}
			this.each(function () {
				var $t = this,
				pos = -1;
				if (!$t.grid) {
					return;
				}
				if (isNaN(col)) {
					$($t.p.colModel).each(function (i) {
						if (this.name === col) {
							pos = i;
							return false;
						}
					});
				} else {
					pos = parseInt(col, 10);
				}
				if (pos >= 0) {
					var ln = $t.rows.length,
					i = 0;
					if (ln && ln > 0) {
						while (i < ln) {
							if ($($t.rows[i]).hasClass('jqgrow')) {
								try {
									val = $.unformat($($t.rows[i].cells[pos]), {
											rowId : $t.rows[i].id,
											colModel : $t.p.colModel[pos]
										}, pos);
								} catch (e) {
									val = $.jgrid.htmlDecode($t.rows[i].cells[pos].innerHTML);
								}
								if (mathopr) {
									sum += parseFloat(val);
								} else if (obj) {
									ret.push({
										id : $t.rows[i].id,
										value : val
									});
								} else {
									ret[i] = val;
								}
							}
							i++;
						}
						if (mathopr) {
							switch (mathopr.toLowerCase()) {
							case 'sum':
								ret = sum;
								break;
							case 'avg':
								ret = sum / ln;
								break;
							case 'count':
								ret = ln;
								break;
							}
						}
					}
				}
			});
			return ret;
		},
		clearGridData : function (clearfooter) {
			return this.each(function () {
				var $t = this;
				if (!$t.grid) {
					return;
				}
				if (typeof clearfooter != 'boolean') {
					clearfooter = false;
				}
				if ($t.p.deepempty) {
					$("#" + $t.p.id + " tbody:first tr:gt(0)").remove();
				} else {
					var trf = $("#" + $t.p.id + " tbody:first tr:first")[0];
					$("#" + $t.p.id + " tbody:first").empty().append(trf);
				}
				if ($t.p.footerrow && clearfooter) {
					$(".ui-jqgrid-ftable td", $t.grid.sDiv).html("&#160;");
				}
				$t.p.selrow = null;
				$t.p.selarrrow = [];
				$t.p.savedRow = [];
				$t.p.records = 0;
				$t.p.page = 1;
				$t.p.lastpage = 0;
				$t.p.reccount = 0;
				$t.p.data = [];
				$t.p_index = {};
				$t.updatepager(true, false);
			});
		},
		getInd : function (rowid, rc) {
			var ret = false,
			rw;
			this.each(function () {
				rw = this.rows.namedItem(rowid);
				if (rw) {
					ret = rc === true ? rw : rw.rowIndex;
				}
			});
			return ret;
		}
	});
})(jQuery);
var showModal = function (h) {
	h.w.show();
};
var closeModal = function (h) {
	h.w.hide().attr("aria-hidden", "true");
	if (h.o) {
		h.o.remove();
	}
};
var hideModal = function (selector, o) {
	o = jQuery.extend({
			jqm : true,
			gb : ''
		}, o || {});
	if (o.onClose) {
		var oncret = o.onClose(selector);
		if (typeof oncret == 'boolean' && !oncret) {
			return;
		}
	}
	if (jQuery.fn.jqm && o.jqm === true) {
		jQuery(selector).attr("aria-hidden", "true").jqmHide();
	} else {
		if (o.gb !== '') {
			try {
				jQuery(".jqgrid-overlay:first", o.gb).hide();
			} catch (e) {}
			
		}
		jQuery(selector).hide().attr("aria-hidden", "true");
	}
};
function findPos(obj) {
	var curleft = 0,
	curtop = 0;
	if (obj.offsetParent) {
		do {
			curleft += obj.offsetLeft;
			curtop += obj.offsetTop;
		} while (obj = obj.offsetParent);
	}
	return [curleft, curtop];
}
var createModal = function (aIDs, content, p, insertSelector, posSelector, appendsel) {
	var mw = document.createElement('div'),
	rtlsup;
	rtlsup = jQuery(p.gbox).attr("dir") == "rtl" ? true : false;
	mw.className = "ui-widget ui-widget-content ui-corner-all ui-jqdialog";
	mw.id = aIDs.themodal;
	var mh = document.createElement('div');
	mh.className = "ui-jqdialog-titlebar ui-widget-header ui-corner-all ui-helper-clearfix";
	mh.id = aIDs.modalhead;
	jQuery(mh).append("<span class='ui-jqdialog-title'>" + p.caption + "</span>");
	var ahr = jQuery("<a href='javascript:void(0)' class='ui-jqdialog-titlebar-close ui-corner-all'></a>").hover(function () {
			ahr.addClass('ui-state-hover');
		}, function () {
			ahr.removeClass('ui-state-hover');
		}).append("<span class='ui-icon ui-icon-closethick'></span>");
	jQuery(mh).append(ahr);
	if (rtlsup) {
		mw.dir = "rtl";
		jQuery(".ui-jqdialog-title", mh).css("float", "right");
		jQuery(".ui-jqdialog-titlebar-close", mh).css("left", 0.3 + "em");
	} else {
		mw.dir = "ltr";
		jQuery(".ui-jqdialog-title", mh).css("float", "left");
		jQuery(".ui-jqdialog-titlebar-close", mh).css("right", 0.3 + "em");
	}
	var mc = document.createElement('div');
	jQuery(mc).addClass("ui-jqdialog-content ui-widget-content").attr("id", aIDs.modalcontent);
	jQuery(mc).append(content);
	mw.appendChild(mc);
	jQuery(mw).prepend(mh);
	if (appendsel === true) {
		jQuery('body').append(mw);
	} else {
		jQuery(mw).insertBefore(insertSelector);
	}
	if (typeof p.jqModal === 'undefined') {
		p.jqModal = true;
	}
	var coord = {};
	if (jQuery.fn.jqm && p.jqModal === true) {
		if (p.left === 0 && p.top === 0) {
			var pos = [];
			pos = findPos(posSelector);
			p.left = pos[0] + 4;
			p.top = pos[1] + 4;
		}
		coord.top = p.top + "px";
		coord.left = p.left;
	} else if (p.left !== 0 || p.top !== 0) {
		coord.left = p.left;
		coord.top = p.top + "px";
	}
	jQuery("a.ui-jqdialog-titlebar-close", mh).click(function (e) {
		var oncm = jQuery("#" + aIDs.themodal).data("onClose") || p.onClose;
		var gboxclose = jQuery("#" + aIDs.themodal).data("gbox") || p.gbox;
		hideModal("#" + aIDs.themodal, {
			gb : gboxclose,
			jqm : p.jqModal,
			onClose : oncm
		});
		return false;
	});
	if (p.width === 0 || !p.width) {
		p.width = 300;
	}
	if (p.height === 0 || !p.height) {
		p.height = 200;
	}
	if (!p.zIndex) {
		p.zIndex = 950;
	}
	var rtlt = 0;
	if (rtlsup && coord.left && !appendsel) {
		rtlt = jQuery(p.gbox).width() - (!isNaN(p.width) ? parseInt(p.width, 10) : 0) - 8;
		coord.left = parseInt(coord.left, 10) + parseInt(rtlt, 10);
	}
	if (coord.left) {
		coord.left += "px";
	}
	jQuery(mw).css(jQuery.extend({
			width : isNaN(p.width) ? "auto" : p.width + "px",
			height : isNaN(p.height) ? "auto" : p.height + "px",
			zIndex : p.zIndex,
			overflow : 'hidden'
		}, coord)).attr({
		tabIndex : "-1",
		"role" : "dialog",
		"aria-labelledby" : aIDs.modalhead,
		"aria-hidden" : "true"
	});
	if (typeof p.drag == 'undefined') {
		p.drag = true;
	}
	if (typeof p.resize == 'undefined') {
		p.resize = true;
	}
	if (p.drag) {
		jQuery(mh).css('cursor', 'move');
		if (jQuery.fn.jqDrag) {
			jQuery(mw).jqDrag(mh);
		} else {
			try {
				jQuery(mw).draggable({
					handle : jQuery("#" + mh.id)
				});
			} catch (e) {}
			
		}
	}
	if (p.resize) {
		if (jQuery.fn.jqResize) {
			jQuery(mw).append("<div class='jqResize ui-resizable-handle ui-resizable-se ui-icon ui-icon-gripsmall-diagonal-se ui-icon-grip-diagonal-se'></div>");
			jQuery("#" + aIDs.themodal).jqResize(".jqResize", aIDs.scrollelm ? "#" + aIDs.scrollelm : false);
		} else {
			try {
				jQuery(mw).resizable({
					handles : 'se, sw',
					alsoResize : aIDs.scrollelm ? "#" + aIDs.scrollelm : false
				});
			} catch (e) {}
			
		}
	}
	if (p.closeOnEscape === true) {
		jQuery(mw).keydown(function (e) {
			if (e.which == 27) {
				var cone = jQuery("#" + aIDs.themodal).data("onClose") || p.onClose;
				hideModal(this, {
					gb : p.gbox,
					jqm : p.jqModal,
					onClose : cone
				});
			}
		});
	}
};
var viewModal = function (selector, o) {
	o = jQuery.extend({
			toTop : true,
			overlay : 10,
			modal : false,
			onShow : showModal,
			onHide : closeModal,
			gbox : '',
			jqm : true,
			jqM : true
		}, o || {});
	if (jQuery.fn.jqm && o.jqm === true) {
		if (o.jqM) {
			jQuery(selector).attr("aria-hidden", "false").jqm(o).jqmShow();
		} else {
			jQuery(selector).attr("aria-hidden", "false").jqmShow();
		}
	} else {
		if (o.gbox !== '') {
			jQuery(".jqgrid-overlay:first", o.gbox).show();
			jQuery(selector).data("gbox", o.gbox);
		}
		jQuery(selector).show().attr("aria-hidden", "false");
		try {
			jQuery(':input:visible', selector)[0].focus();
		} catch (_) {}
		
	}
};
function info_dialog(caption, content, c_b, modalopt) {
	var mopt = {
		width : 290,
		height : 'auto',
		dataheight : 'auto',
		drag : true,
		resize : false,
		caption : "<b>" + caption + "</b>",
		left : 250,
		top : 170,
		zIndex : 1000,
		jqModal : true,
		modal : false,
		closeOnEscape : true,
		align : 'center',
		buttonalign : 'center',
		buttons : []
	};
	jQuery.extend(mopt, modalopt || {});
	var jm = mopt.jqModal;
	if (jQuery.fn.jqm && !jm) {
		jm = false;
	}
	var buttstr = "";
	if (mopt.buttons.length > 0) {
		for (var i = 0; i < mopt.buttons.length; i++) {
			if (typeof mopt.buttons[i].id == "undefined") {
				mopt.buttons[i].id = "info_button_" + i;
			}
			buttstr += "<a href='javascript:void(0)' id='" + mopt.buttons[i].id + "' class='fm-button ui-state-default ui-corner-all'>" + mopt.buttons[i].text + "</a>";
		}
	}
	var dh = isNaN(mopt.dataheight) ? mopt.dataheight : mopt.dataheight + "px",
	cn = "text-align:" + mopt.align + ";";
	var cnt = "<div id='info_id'>";
	cnt += "<div id='infocnt' style='margin:0px;padding-bottom:1em;width:100%;overflow:auto;position:relative;height:" + dh + ";" + cn + "'>" + content + "</div>";
	cnt += c_b ? "<div class='ui-widget-content ui-helper-clearfix' style='text-align:" + mopt.buttonalign + ";padding-bottom:0.8em;padding-top:0.5em;background-image: none;border-width: 1px 0 0 0;'><a href='javascript:void(0)' id='closedialog' class='fm-button ui-state-default ui-corner-all'>" + c_b + "</a>" + buttstr + "</div>" : buttstr !== "" ? "<div class='ui-widget-content ui-helper-clearfix' style='text-align:" + mopt.buttonalign + ";padding-bottom:0.8em;padding-top:0.5em;background-image: none;border-width: 1px 0 0 0;'>" + buttstr + "</div>" : "";
	cnt += "</div>";
	try {
		if (jQuery("#info_dialog").attr("aria-hidden") == "false") {
			hideModal("#info_dialog", {
				jqm : jm
			});
		}
		jQuery("#info_dialog").remove();
	} catch (e) {}
	createModal({
		themodal : 'info_dialog',
		modalhead : 'info_head',
		modalcontent : 'info_content',
		scrollelm : 'infocnt'
	}, cnt, mopt, '', '', true);
	if (buttstr) {
		jQuery.each(mopt.buttons, function (i) {
			jQuery("#" + this.id, "#info_id").bind('click', function () {
				mopt.buttons[i].onClick.call(jQuery("#info_dialog"));
				return false;
			});
		});
	}
	jQuery("#closedialog", "#info_id").click(function (e) {
		hideModal("#info_dialog", {
			jqm : jm
		});
		return false;
	});
	jQuery(".fm-button", "#info_dialog").hover(function () {
		jQuery(this).addClass('ui-state-hover');
	}, function () {
		jQuery(this).removeClass('ui-state-hover');
	});
	if (jQuery.isFunction(mopt.beforeOpen)) {
		mopt.beforeOpen();
	}
	viewModal("#info_dialog", {
		onHide : function (h) {
			h.w.hide().remove();
			if (h.o) {
				h.o.remove();
			}
		},
		modal : mopt.modal,
		jqm : jm
	});
	if (jQuery.isFunction(mopt.afterOpen)) {
		mopt.afterOpen();
	}
	try {
		jQuery("#info_dialog").focus();
	} catch (e) {}
	
}
function createEl(eltype, options, vl, autowidth, ajaxso) {
	var elem = "";
	if (options.defaultValue) {
		delete options.defaultValue;
	}
	function bindEv(el, opt) {
		if (jQuery.isFunction(opt.dataInit)) {
			el.id = opt.id;
			opt.dataInit(el);
			delete opt.id;
			delete opt.dataInit;
		}
		if (opt.dataEvents) {
			jQuery.each(opt.dataEvents, function () {
				if (this.data !== undefined) {
					jQuery(el).bind(this.type, this.data, this.fn);
				} else {
					jQuery(el).bind(this.type, this.fn);
				}
			});
			delete opt.dataEvents;
		}
		return opt;
	}
	switch (eltype) {
	case "textarea":
		elem = document.createElement("textarea");
		if (autowidth) {
			if (!options.cols) {
				jQuery(elem).css({
					width : "98%"
				});
			}
		} else if (!options.cols) {
			options.cols = 20;
		}
		if (!options.rows) {
			options.rows = 2;
		}
		if (vl == '&nbsp;' || vl == '&#160;' || (vl.length == 1 && vl.charCodeAt(0) == 160)) {
			vl = "";
		}
		elem.value = vl;
		options = bindEv(elem, options);
		jQuery(elem).attr(options).attr({
			"role" : "textbox",
			"multiline" : "true"
		});
		break;
	case "checkbox":
		elem = document.createElement("input");
		elem.type = "checkbox";
		if (!options.value) {
			var vl1 = vl.toLowerCase();
			if (vl1.search(/(false|0|no|off|undefined)/i) < 0 && vl1 !== "") {
				elem.checked = true;
				elem.defaultChecked = true;
				elem.value = vl;
			} else {
				elem.value = "on";
			}
			jQuery(elem).attr("offval", "off");
		} else {
			var cbval = options.value.split(":");
			if (vl === cbval[0]) {
				elem.checked = true;
				elem.defaultChecked = true;
			}
			elem.value = cbval[0];
			jQuery(elem).attr("offval", cbval[1]);
			try {
				delete options.value;
			} catch (e) {}
			
		}
		options = bindEv(elem, options);
		jQuery(elem).attr(options).attr("role", "checkbox");
		break;
	case "select":
		elem = document.createElement("select");
		elem.setAttribute("role", "select");
		var msl,
		ovm = [];
		if (options.multiple === true) {
			msl = true;
			elem.multiple = "multiple";
			jQuery(elem).attr("aria-multiselectable", "true");
		} else {
			msl = false;
		}
		if (typeof(options.dataUrl) != "undefined") {
			jQuery.ajax(jQuery.extend({
					url : options.dataUrl,
					type : "GET",
					dataType : "html",
					success : function (data, status) {
						try {
							delete options.dataUrl;
							delete options.value;
						} catch (e) {}
						var a;
						if (typeof(options.buildSelect) != "undefined") {
							var b = options.buildSelect(data);
							a = jQuery(b).html();
							delete options.buildSelect;
						} else {
							a = jQuery(data).html();
						}
						if (a) {
							jQuery(elem).append(a);
							options = bindEv(elem, options);
							if (typeof options.size === 'undefined') {
								options.size = msl ? 3 : 1;
							}
							if (msl) {
								ovm = vl.split(",");
								ovm = jQuery.map(ovm, function (n) {
										return jQuery.trim(n);
									});
							} else {
								ovm[0] = jQuery.trim(vl);
							}
							jQuery(elem).attr(options);
							setTimeout(function () {
								jQuery("option", elem).each(function (i) {
									if (i === 0) {
										this.selected = "";
									}
									jQuery(this).attr("role", "option");
									if (jQuery.inArray(jQuery.trim(jQuery(this).text()), ovm) > -1 || jQuery.inArray(jQuery.trim(jQuery(this).val()), ovm) > -1) {
										this.selected = "selected";
										if (!msl) {
											return false;
										}
									}
								});
							}, 0);
						}
					}
				}, ajaxso || {}));
		} else if (options.value) {
			var i;
			if (msl) {
				ovm = vl.split(",");
				ovm = jQuery.map(ovm, function (n) {
						return jQuery.trim(n);
					});
				if (typeof options.size === 'undefined') {
					options.size = 3;
				}
			} else {
				options.size = 1;
			}
			if (typeof options.value === 'function') {
				options.value = options.value();
			}
			var so,
			sv,
			ov;
			if (typeof options.value === 'string') {
				so = options.value.split(";");
				for (i = 0; i < so.length; i++) {
					sv = so[i].split(":");
					if (sv.length > 2) {
						sv[1] = jQuery.map(sv, function (n, i) {
								if (i > 0) {
									return n;
								}
							}).join(":");
					}
					ov = document.createElement("option");
					ov.setAttribute("role", "option");
					ov.value = sv[0];
					ov.innerHTML = sv[1];
					if (!msl && (jQuery.trim(sv[0]) == jQuery.trim(vl) || jQuery.trim(sv[1]) == jQuery.trim(vl))) {
						ov.selected = "selected";
					}
					if (msl && (jQuery.inArray(jQuery.trim(sv[1]), ovm) > -1 || jQuery.inArray(jQuery.trim(sv[0]), ovm) > -1)) {
						ov.selected = "selected";
					}
					elem.appendChild(ov);
				}
			} else if (typeof options.value === 'object') {
				var oSv = options.value;
				for (var key in oSv) {
					if (oSv.hasOwnProperty(key)) {
						ov = document.createElement("option");
						ov.setAttribute("role", "option");
						ov.value = key;
						ov.innerHTML = oSv[key];
						if (!msl && (jQuery.trim(key) == jQuery.trim(vl) || jQuery.trim(oSv[key]) == jQuery.trim(vl))) {
							ov.selected = "selected";
						}
						if (msl && (jQuery.inArray(jQuery.trim(oSv[key]), ovm) > -1 || jQuery.inArray(jQuery.trim(key), ovm) > -1)) {
							ov.selected = "selected";
						}
						elem.appendChild(ov);
					}
				}
			}
			options = bindEv(elem, options);
			try {
				delete options.value;
			} catch (e) {}
			jQuery(elem).attr(options);
		}
		break;
	case "text":
	case "password":
	case "button":
		var role;
		if (eltype == "button") {
			role = "button";
		} else {
			role = "textbox";
		}
		elem = document.createElement("input");
		elem.type = eltype;
		elem.value = vl;
		options = bindEv(elem, options);
		if (eltype != "button") {
			if (autowidth) {
				if (!options.size) {
					jQuery(elem).css({
						width : "98%"
					});
				}
			} else if (!options.size) {
				options.size = 20;
			}
		}
		jQuery(elem).attr(options).attr("role", role);
		break;
	case "image":
	case "file":
		elem = document.createElement("input");
		elem.type = eltype;
		options = bindEv(elem, options);
		jQuery(elem).attr(options);
		break;
	case "custom":
		elem = document.createElement("span");
		try {
			if (jQuery.isFunction(options.custom_element)) {
				var celm = options.custom_element.call(this, vl, options);
				if (celm) {
					celm = jQuery(celm).addClass("customelement").attr({
							id : options.id,
							name : options.name
						});
					jQuery(elem).empty().append(celm);
				} else {
					throw "e2";
				}
			} else {
				throw "e1";
			}
		} catch (e) {
			if (e == "e1") {
				info_dialog(jQuery.jgrid.errors.errcap, "function 'custom_element' " + jQuery.jgrid.edit.msg.nodefined, jQuery.jgrid.edit.bClose);
			}
			if (e == "e2") {
				info_dialog(jQuery.jgrid.errors.errcap, "function 'custom_element' " + jQuery.jgrid.edit.msg.novalue, jQuery.jgrid.edit.bClose);
			} else {
				info_dialog(jQuery.jgrid.errors.errcap, typeof(e) === "string" ? e : e.message, jQuery.jgrid.edit.bClose);
			}
		}
		break;
	}
	return elem;
}
function daysInFebruary(year) {
	return (((year % 4 === 0) && (year % 100 !== 0 || (year % 400 === 0))) ? 29 : 28);
}
function DaysArray(n) {
	for (var i = 1; i <= n; i++) {
		this[i] = 31;
		if (i == 4 || i == 6 || i == 9 || i == 11) {
			this[i] = 30;
		}
		if (i == 2) {
			this[i] = 29;
		}
	}
	return this;
}
function checkDate(format, date) {
	var tsp = {},
	sep;
	format = format.toLowerCase();
	if (format.indexOf("/") != -1) {
		sep = "/";
	} else if (format.indexOf("-") != -1) {
		sep = "-";
	} else if (format.indexOf(".") != -1) {
		sep = ".";
	} else {
		sep = "/";
	}
	format = format.split(sep);
	date = date.split(sep);
	if (date.length != 3) {
		return false;
	}
	var j = -1,
	yln,
	dln = -1,
	mln = -1;
	for (var i = 0; i < format.length; i++) {
		var dv = isNaN(date[i]) ? 0 : parseInt(date[i], 10);
		tsp[format[i]] = dv;
		yln = format[i];
		if (yln.indexOf("y") != -1) {
			j = i;
		}
		if (yln.indexOf("m") != -1) {
			mln = i;
		}
		if (yln.indexOf("d") != -1) {
			dln = i;
		}
	}
	if (format[j] == "y" || format[j] == "yyyy") {
		yln = 4;
	} else if (format[j] == "yy") {
		yln = 2;
	} else {
		yln = -1;
	}
	var daysInMonth = DaysArray(12);
	var strDate;
	if (j === -1) {
		return false;
	} else {
		strDate = tsp[format[j]].toString();
		if (yln == 2 && strDate.length == 1) {
			yln = 1;
		}
		if (strDate.length != yln || (tsp[format[j]] === 0 && date[j] != "00")) {
			return false;
		}
	}
	if (mln === -1) {
		return false;
	} else {
		strDate = tsp[format[mln]].toString();
		if (strDate.length < 1 || tsp[format[mln]] < 1 || tsp[format[mln]] > 12) {
			return false;
		}
	}
	if (dln === -1) {
		return false;
	} else {
		strDate = tsp[format[dln]].toString();
		if (strDate.length < 1 || tsp[format[dln]] < 1 || tsp[format[dln]] > 31 || (tsp[format[mln]] == 2 && tsp[format[dln]] > daysInFebruary(tsp[format[j]])) || tsp[format[dln]] > daysInMonth[tsp[format[mln]]]) {
			return false;
		}
	}
	return true;
}
function isEmpty(val) {
	if (val.match(/^\s+$/) || val === "") {
		return true;
	} else {
		return false;
	}
}
function checkTime(time) {
	var re = /^(\d{1,2}):(\d{2})([ap]m)?$/,
	regs;
	if (!isEmpty(time)) {
		regs = time.match(re);
		if (regs) {
			if (regs[3]) {
				if (regs[1] < 1 || regs[1] > 12) {
					return false;
				}
			} else {
				if (regs[1] > 23) {
					return false;
				}
			}
			if (regs[2] > 59) {
				return false;
			}
		} else {
			return false;
		}
	}
	return true;
}
function checkValues(val, valref, g) {
	var edtrul,
	i,
	nm,
	dft,
	len;
	if (typeof(valref) == 'string') {
		for (i = 0, len = g.p.colModel.length; i < len; i++) {
			if (g.p.colModel[i].name == valref) {
				edtrul = g.p.colModel[i].editrules;
				valref = i;
				try {
					nm = g.p.colModel[i].formoptions.label;
				} catch (e) {}
				break;
			}
		}
	} else if (valref >= 0) {
		edtrul = g.p.colModel[valref].editrules;
	}
	if (edtrul) {
		if (!nm) {
			nm = g.p.colNames[valref];
		}
		if (edtrul.required === true) {
			if (isEmpty(val)) {
				return [false, nm + ": " + jQuery.jgrid.edit.msg.required, ""];
			}
		}
		var rqfield = edtrul.required === false ? false : true;
		if (edtrul.number === true) {
			if (!(rqfield === false && isEmpty(val))) {
				if (isNaN(val)) {
					return [false, nm + ": " + jQuery.jgrid.edit.msg.number, ""];
				}
			}
		}
		if (typeof edtrul.minValue != 'undefined' && !isNaN(edtrul.minValue)) {
			if (parseFloat(val) < parseFloat(edtrul.minValue)) {
				return [false, nm + ": " + jQuery.jgrid.edit.msg.minValue + " " + edtrul.minValue, ""];
			}
		}
		if (typeof edtrul.maxValue != 'undefined' && !isNaN(edtrul.maxValue)) {
			if (parseFloat(val) > parseFloat(edtrul.maxValue)) {
				return [false, nm + ": " + jQuery.jgrid.edit.msg.maxValue + " " + edtrul.maxValue, ""];
			}
		}
		var filter;
		if (edtrul.email === true) {
			if (!(rqfield === false && isEmpty(val))) {
				filter = /^((([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))@((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?$/i;
				if (!filter.test(val)) {
					return [false, nm + ": " + jQuery.jgrid.edit.msg.email, ""];
				}
			}
		}
		if (edtrul.integer === true) {
			if (!(rqfield === false && isEmpty(val))) {
				if (isNaN(val)) {
					return [false, nm + ": " + jQuery.jgrid.edit.msg.integer, ""];
				}
				if ((val % 1 !== 0) || (val.indexOf('.') != -1)) {
					return [false, nm + ": " + jQuery.jgrid.edit.msg.integer, ""];
				}
			}
		}
		if (edtrul.date === true) {
			if (!(rqfield === false && isEmpty(val))) {
				if (g.p.colModel[valref].formatoptions && g.p.colModel[valref].formatoptions.newformat) {
					dft = g.p.colModel[valref].formatoptions.newformat;
				} else {
					dft = g.p.colModel[valref].datefmt || "Y-m-d";
				}
				if (!checkDate(dft, val)) {
					return [false, nm + ": " + jQuery.jgrid.edit.msg.date + " - " + dft, ""];
				}
			}
		}
		if (edtrul.time === true) {
			if (!(rqfield === false && isEmpty(val))) {
				if (!checkTime(val)) {
					return [false, nm + ": " + jQuery.jgrid.edit.msg.date + " - hh:mm (am/pm)", ""];
				}
			}
		}
		if (edtrul.url === true) {
			if (!(rqfield === false && isEmpty(val))) {
				filter = /^(((https?)|(ftp)):\/\/([\-\w]+\.)+\w{2,3}(\/[%\-\w]+(\.\w{2,})?)*(([\w\-\.\?\\\/+@&#;`~=%!]*)(\.\w{2,})?)*\/?)/i;
				if (!filter.test(val)) {
					return [false, nm + ": " + jQuery.jgrid.edit.msg.url, ""];
				}
			}
		}
		if (edtrul.custom === true) {
			if (!(rqfield === false && isEmpty(val))) {
				if (jQuery.isFunction(edtrul.custom_func)) {
					var ret = edtrul.custom_func.call(g, val, nm);
					if (jQuery.isArray(ret)) {
						return ret;
					} else {
						return [false, jQuery.jgrid.edit.msg.customarray, ""];
					}
				} else {
					return [false, jQuery.jgrid.edit.msg.customfcheck, ""];
				}
			}
		}
	}
	return [true, "", ""];
};
(function ($) {
	var rp_ge = null;
	$.jgrid.extend({
		navGrid : function (elem, o, pEdit, pAdd, pDel, pSearch, pView) {
			o = $.extend({
					edit : true,
					editicon : "ui-icon-pencil",
					add : true,
					addicon : "ui-icon-plus",
					del : true,
					delicon : "ui-icon-trash",
					search : true,
					searchicon : "ui-icon-search",
					refresh : true,
					refreshicon : "ui-icon-refresh",
					refreshstate : 'firstpage',
					view : false,
					viewicon : "ui-icon-document",
					position : "left",
					closeOnEscape : true,
					beforeRefresh : null,
					afterRefresh : null,
					cloneToTop : false
				}, $.jgrid.nav, o || {});
			return this.each(function () {
				var alertIDs = {
					themodal : 'alertmod',
					modalhead : 'alerthd',
					modalcontent : 'alertcnt'
				},
				$t = this,
				vwidth,
				vheight,
				twd,
				tdw;
				if (!$t.grid || typeof elem != 'string') {
					return;
				}
				if ($("#" + alertIDs.themodal).html() === null) {
					if (typeof window.innerWidth != 'undefined') {
						vwidth = window.innerWidth;
						vheight = window.innerHeight;
					} else if (typeof document.documentElement != 'undefined' && typeof document.documentElement.clientWidth != 'undefined' && document.documentElement.clientWidth !== 0) {
						vwidth = document.documentElement.clientWidth;
						vheight = document.documentElement.clientHeight;
					} else {
						vwidth = 1024;
						vheight = 768;
					}
					createModal(alertIDs, "<div>" + o.alerttext + "</div><span tabindex='0'><span tabindex='-1' id='jqg_alrt'></span></span>", {
						gbox : "#gbox_" + $t.p.id,
						jqModal : true,
						drag : true,
						resize : true,
						caption : o.alertcap,
						top : vheight / 2 - 25,
						left : vwidth / 2 - 100,
						width : 200,
						height : 'auto',
						closeOnEscape : o.closeOnEscape
					}, "", "", true);
				}
				var clone = 1;
				if (o.cloneToTop && $t.p.toppager) {
					clone = 2;
				}
				for (var i = 0; i < clone; i++) {
					var tbd,
					navtbl = $("<table cellspacing='0' cellpadding='0' border='0' class='ui-pg-table22 navtable' style='float:left;table-layout:auto;'><tbody><tr></tr></tbody></table>"),
					sep = "<td class='ui-pg-button ui-state-disabled' style='width:4px;'><span class='ui-separator'></span></td>",
					pgid,
					elemids;
					if (i === 0) {
						pgid = elem;
						elemids = $t.p.id;
						if (pgid == $t.p.toppager) {
							elemids += "_top";
							clone = 1;
						}
					} else {
						pgid = $t.p.toppager;
						elemids = $t.p.id + "_top";
					}
					if ($t.p.direction == "rtl") {
						$(navtbl).attr("dir", "rtl").css("float", "right");
					}
					if (o.add) {
						pAdd = pAdd || {};
						tbd = $("<td class='ui-pg-button ui-corner-all'></td>");
						$(tbd).append("<div class='ui-pg-div'><span class='ui-icon " + o.addicon + "'></span>" + o.addtext + "</div>");
						$("tr", navtbl).append(tbd);
						$(tbd, navtbl).attr({
							"title" : o.addtitle || "",
							id : pAdd.id || "add_" + elemids
						}).click(function () {
							if (!$(this).hasClass('ui-state-disabled')) {
								if (typeof o.addfunc == 'function') {
									o.addfunc();
								} else {
									$($t).jqGrid("editGridRow", "new", pAdd);
								}
							}
							return false;
						}).hover(function () {
							if (!$(this).hasClass('ui-state-disabled')) {
								$(this).addClass("ui-state-hover");
							}
						}, function () {
							$(this).removeClass("ui-state-hover");
						});
						tbd = null;
					}
					if (o.edit) {
						tbd = $("<td class='ui-pg-button ui-corner-all'></td>");
						pEdit = pEdit || {};
						$(tbd).append("<div class='ui-pg-div'><span class='ui-icon " + o.editicon + "'></span>" + o.edittext + "</div>");
						$("tr", navtbl).append(tbd);
						$(tbd, navtbl).attr({
							"title" : o.edittitle || "",
							id : pEdit.id || "edit_" + elemids
						}).click(function () {
							if (!$(this).hasClass('ui-state-disabled')) {
								var sr = $t.p.selrow;
								if (sr) {
									if (typeof o.editfunc == 'function') {
										o.editfunc(sr);
									} else {
										$($t).jqGrid("editGridRow", sr, pEdit);
									}
								} else {
									viewModal("#" + alertIDs.themodal, {
										gbox : "#gbox_" + $t.p.id,
										jqm : true
									});
									$("#jqg_alrt").focus();
								}
							}
							return false;
						}).hover(function () {
							if (!$(this).hasClass('ui-state-disabled')) {
								$(this).addClass("ui-state-hover");
							}
						}, function () {
							$(this).removeClass("ui-state-hover");
						});
						tbd = null;
					}
					if (o.view) {
						tbd = $("<td class='ui-pg-button ui-corner-all'></td>");
						pView = pView || {};
						$(tbd).append("<div class='ui-pg-div'><span class='ui-icon " + o.viewicon + "'></span>" + o.viewtext + "</div>");
						$("tr", navtbl).append(tbd);
						$(tbd, navtbl).attr({
							"title" : o.viewtitle || "",
							id : pView.id || "view_" + elemids
						}).click(function () {
							if (!$(this).hasClass('ui-state-disabled')) {
								var sr = $t.p.selrow;
								if (sr) {
									$($t).jqGrid("viewGridRow", sr, pView);
								} else {
									viewModal("#" + alertIDs.themodal, {
										gbox : "#gbox_" + $t.p.id,
										jqm : true
									});
									$("#jqg_alrt").focus();
								}
							}
							return false;
						}).hover(function () {
							if (!$(this).hasClass('ui-state-disabled')) {
								$(this).addClass("ui-state-hover");
							}
						}, function () {
							$(this).removeClass("ui-state-hover");
						});
						tbd = null;
					}
					if (o.del) {
						tbd = $("<td class='ui-pg-button ui-corner-all'></td>");
						pDel = pDel || {};
						$(tbd).append("<div class='ui-pg-div'><span class='ui-icon " + o.delicon + "'></span>" + o.deltext + "</div>");
						$("tr", navtbl).append(tbd);
						$(tbd, navtbl).attr({
							"title" : o.deltitle || "",
							id : pDel.id || "del_" + elemids
						}).click(function () {
							if (!$(this).hasClass('ui-state-disabled')) {
								var dr;
								if ($t.p.multiselect) {
									dr = $t.p.selarrrow;
									if (dr.length === 0) {
										dr = null;
									}
								} else {
									dr = $t.p.selrow;
								}
								if (dr) {
									if ("function" == typeof o.delfunc) {
										o.delfunc(dr);
									} else {
										$($t).jqGrid("delGridRow", dr, pDel);
									}
								} else {
									viewModal("#" + alertIDs.themodal, {
										gbox : "#gbox_" + $t.p.id,
										jqm : true
									});
									$("#jqg_alrt").focus();
								}
							}
							return false;
						}).hover(function () {
							if (!$(this).hasClass('ui-state-disabled')) {
								$(this).addClass("ui-state-hover");
							}
						}, function () {
							$(this).removeClass("ui-state-hover");
						});
						tbd = null;
					}
					if (o.add || o.edit || o.del || o.view) {
						$("tr", navtbl).append(sep);
					}
					if (o.search) {
						tbd = $("<td class='ui-pg-button ui-corner-all'></td>");
						pSearch = pSearch || {};
						$(tbd).append("<div class='ui-pg-div'><span class='ui-icon " + o.searchicon + "'></span>" + o.searchtext + "</div>");
						$("tr", navtbl).append(tbd);
						$(tbd, navtbl).attr({
							"title" : o.searchtitle || "",
							id : pSearch.id || "search_" + elemids
						}).click(function () {
							if (!$(this).hasClass('ui-state-disabled')) {
								$($t).jqGrid("searchGrid", pSearch);
							}
							return false;
						}).hover(function () {
							if (!$(this).hasClass('ui-state-disabled')) {
								$(this).addClass("ui-state-hover");
							}
						}, function () {
							$(this).removeClass("ui-state-hover");
						});
						tbd = null;
					}
					if (o.refresh) {
						tbd = $("<td class='ui-pg-button ui-corner-all'></td>");
						$(tbd).append("<div class='ui-pg-div'><span class='ui-icon " + o.refreshicon + "'></span>" + o.refreshtext + "</div>");
						$("tr", navtbl).append(tbd);
						$(tbd, navtbl).attr({
							"title" : o.refreshtitle || "",
							id : "refresh_" + elemids
						}).click(function () {
							if (!$(this).hasClass('ui-state-disabled')) {
								if ($.isFunction(o.beforeRefresh)) {
									o.beforeRefresh();
								}
								$t.p.search = false;
								try {
									var gID = $t.p.id;
									$("#fbox_" + gID).searchFilter().reset({
										"reload" : false
									});
									if ($.isFunction($t.clearToolbar)) {
										$t.clearToolbar(false);
									}
								} catch (e) {}
								switch (o.refreshstate) {
								case 'firstpage':
									$($t).trigger("reloadGrid", [{
												page : 1
											}
										]);
									break;
								case 'current':
									$($t).trigger("reloadGrid", [{
												current : true
											}
										]);
									break;
								}
								if ($.isFunction(o.afterRefresh)) {
									o.afterRefresh();
								}
							}
							return false;
						}).hover(function () {
							if (!$(this).hasClass('ui-state-disabled')) {
								$(this).addClass("ui-state-hover");
							}
						}, function () {
							$(this).removeClass("ui-state-hover");
						});
						tbd = null;
					}
					tdw = $(".ui-jqgrid").css("font-size") || "11px";
					$('body').append("<div id='testpg2' class='ui-jqgrid ui-widget ui-widget-content' style='font-size:" + tdw + ";visibility:hidden;' ></div>");
					twd = $(navtbl).clone().appendTo("#testpg2").width();
					$("#testpg2").remove();
					$(pgid + "_" + o.position, pgid).append(navtbl);
					if ($t.p._nvtd) {
						if (twd > $t.p._nvtd[0]) {
							$(pgid + "_" + o.position, pgid).width(twd);
							$t.p._nvtd[0] = twd;
						}
						$t.p._nvtd[1] = twd;
					}
					tdw = null;
					twd = null;
					navtbl = null;
				}
			});
		},
		navButtonAdd : function (elem, p) {
			p = $.extend({
					caption : "newButton",
					title : '',
					buttonicon : 'ui-icon-newwin',
					onClickButton : null,
					position : "last",
					cursor : 'pointer'
				}, p || {});
			return this.each(function () {
				if (!this.grid) {
					return;
				}
				if (elem.indexOf("#") !== 0) {
					elem = "#" + elem;
				}
				var findnav = $(".navtable", elem)[0],
				$t = this;
				if (findnav) {
					var tbd = $("<td></td>");
					if (p.buttonicon.toString().toUpperCase() == "NONE") {
						$(tbd).addClass('ui-pg-button ui-corner-all').append("<div class='ui-pg-div'>" + p.caption + "</div>");
					} else {
						if (p.caption == '删除')
							$(tbd).addClass('ui-pg-button ui-corner-all').append("<div class='ui-pg-div'><img src='" + contextPath + "/images/del.gif' ></div>");
						else if (p.caption == '获取代码') {
							var uidlog = $('#uidlog').val();
							$(tbd).addClass('ui-pg-button ui-corner-all').append("<div class='ui-pg-div'><img src='" + contextPath + "/images/get_code.gif' id='get_code'  onclick='sendlogtoserver(108,2,-1," + uidlog + ")'></div>");
							
						} else if (p.caption == '暂停')
							$(tbd).addClass('ui-pg-button ui-corner-all').append("<div class='ui-pg-div'><img src='" + contextPath + "/images/stop.gif'></div>");
						else if (p.caption == '开启')
							$(tbd).addClass('ui-pg-button ui-corner-all').append("<div class='ui-pg-div'><img src='" + contextPath + "/images/start.gif'></div>");
						else if (p.caption == '删除ad')
							$(tbd).addClass('ui-pg-button ui-corner-all').append("<div class='ui-pg-div'><img src='" + contextPath + "/images/dell_a.gif'></div>");
						else if (p.caption == '取消')
							$(tbd).addClass('ui-pg-button ui-corner-all').append("<div class='ui-pg-div'><img src='" + contextPath + "/images/cancel.gif'></div>");
						else if (p.caption == '恢复')
							$(tbd).addClass('ui-pg-button ui-corner-all').append("<div class='ui-pg-div'><img src='" + contextPath + "/images/list/react.gif'></div>");
						else if (p.caption == 'top')
							$(tbd).addClass('ui-pg-button ui-corner-all').append("<div class='ui-pg-div'><img src='" + contextPath + "/images/toptop.gif'></div>");
						else if (p.caption == '提交')
							$(tbd).addClass('ui-pg-button ui-corner-all').append("<div class='ui-pg-div'><img src='" + contextPath + "/images/commit.gif'></div>");
						else if (p.caption == 'cacletop')
							$(tbd).addClass('ui-pg-button ui-corner-all').append("<div class='ui-pg-div'><img src='" + contextPath + "/images/cacletop.gif'></div>");
						else if (p.caption == '完成')
							$(tbd).addClass('ui-pg-button ui-corner-all').append("<div class='ui-pg-div'><img src='" + contextPath + "/images/over_x.gif'></div>");
						else if (p.caption == '确定')
							$(tbd).addClass('ui-pg-button ui-corner-all').append("<div class='ui-pg-div'><img src='" + contextPath + "/images/queding_x.gif'></div>");
						}
					if (p.id) {
						$(tbd).attr("id", p.id);
					}
					if (p.position == 'first') {
						if (findnav.rows[0].cells.length === 0) {
							$("tr", findnav).append(tbd);
						} else {
							$("tr td:eq(0)", findnav).before(tbd);
						}
					} else {
						$("tr", findnav).append(tbd);
					}
					$(tbd, findnav).attr("title", p.title || "").click(function (e) {
						if (!$(this).hasClass('ui-state-disabled')) {
							if ($.isFunction(p.onClickButton)) {
								p.onClickButton.call($t, e);
							}
						}
						return false;
					}).hover(function () {
						if (!$(this).hasClass('ui-state-disabled')) {}
						
					}, function () {
						$(this).removeClass("ui-state-hover");
					});
				}
			});
		},
		navSeparatorAdd : function (elem, p) {
			p = $.extend({
					sepclass : "ui-separator",
					sepcontent : ''
				}, p || {});
			return this.each(function () {
				if (!this.grid) {
					return;
				}
				if (elem.indexOf("#") !== 0) {
					elem = "#" + elem;
				}
				var findnav = $(".navtable", elem)[0];
				if (findnav) {
					var sep = "<td class='ui-pg-button ui-state-disabled' style='width:4px;'><span class='" + p.sepclass + "'></span>" + p.sepcontent + "</td>";
					$("tr", findnav).append(sep);
				}
			});
		},
		GridToForm : function (rowid, formid) {
			return this.each(function () {
				var $t = this;
				if (!$t.grid) {
					return;
				}
				var rowdata = $($t).jqGrid("getRowData", rowid);
				if (rowdata) {
					for (var i in rowdata) {
						if ($("[name=" + i + "]", formid).is("input:radio") || $("[name=" + i + "]", formid).is("input:checkbox")) {
							$("[name=" + i + "]", formid).each(function () {
								if ($(this).val() == rowdata[i]) {
									$(this).attr("checked", "checked");
								} else {
									$(this).attr("checked", "");
								}
							});
						} else {
							$("[name=" + i + "]", formid).val(rowdata[i]);
						}
					}
				}
			});
		},
		FormToGrid : function (rowid, formid, mode, position) {
			return this.each(function () {
				var $t = this;
				if (!$t.grid) {
					return;
				}
				if (!mode) {
					mode = 'set';
				}
				if (!position) {
					position = 'first';
				}
				var fields = $(formid).serializeArray();
				var griddata = {};
				$.each(fields, function (i, field) {
					griddata[field.name] = field.value;
				});
				if (mode == 'add') {
					$($t).jqGrid("addRowData", rowid, griddata, position);
				} else if (mode == 'set') {
					$($t).jqGrid("setRowData", rowid, griddata);
				}
			});
		}
	});
})(jQuery); ;
(function ($) {
	$.jgrid.extend({
		getColProp : function (colname) {
			var ret = {},
			$t = this[0];
			if (!$t.grid) {
				return;
			}
			var cM = $t.p.colModel;
			for (var i = 0; i < cM.length; i++) {
				if (cM[i].name == colname) {
					ret = cM[i];
					break;
				}
			}
			return ret;
		},
		setColProp : function (colname, obj) {
			return this.each(function () {
				if (this.grid) {
					if (obj) {
						var cM = this.p.colModel;
						for (var i = 0; i < cM.length; i++) {
							if (cM[i].name == colname) {
								$.extend(this.p.colModel[i], obj);
								break;
							}
						}
					}
				}
			});
		},
		sortGrid : function (colname, reload, sor) {
			return this.each(function () {
				var $t = this,
				idx = -1;
				if (!$t.grid) {
					return;
				}
				if (!colname) {
					colname = $t.p.sortname;
				}
				for (var i = 0; i < $t.p.colModel.length; i++) {
					if ($t.p.colModel[i].index == colname || $t.p.colModel[i].name == colname) {
						idx = i;
						break;
					}
				}
				if (idx != -1) {
					var sort = $t.p.colModel[idx].sortable;
					if (typeof sort !== 'boolean') {
						sort = true;
					}
					if (typeof reload !== 'boolean') {
						reload = false;
					}
					if (sort) {
						$t.sortData("jqgh_" + colname, idx, reload, sor);
					}
				}
			});
		},
		GridDestroy : function () {
			return this.each(function () {
				if (this.grid) {
					if (this.p.pager) {
						$(this.p.pager).remove();
					}
					var gid = this.id;
					try {
						$("#gbox_" + gid).remove();
					} catch (_) {}
					
				}
			});
		},
		GridUnload : function () {
			return this.each(function () {
				if (!this.grid) {
					return;
				}
				var defgrid = {
					id : $(this).attr('id'),
					cl : $(this).attr('class')
				};
				if (this.p.pager) {
					$(this.p.pager).empty().removeClass("ui-state-default ui-jqgrid-pager corner-bottom");
				}
				var newtable = document.createElement('table');
				$(newtable).attr({
					id : defgrid.id
				});
				newtable.className = defgrid.cl;
				var gid = this.id;
				$(newtable).removeClass("ui-jqgrid-btable");
				if ($(this.p.pager).parents("#gbox_" + gid).length === 1) {
					$(newtable).insertBefore("#gbox_" + gid).show();
					$(this.p.pager).insertBefore("#gbox_" + gid);
				} else {
					$(newtable).insertBefore("#gbox_" + gid).show();
				}
				$("#gbox_" + gid).remove();
			});
		},
		setGridState : function (state) {
			return this.each(function () {
				if (!this.grid) {
					return;
				}
				var $t = this;
				if (state == 'hidden') {
					$(".ui-jqgrid-bdiv, .ui-jqgrid-hdiv", "#gview_" + $t.p.id).slideUp("fast");
					if ($t.p.pager) {
						$($t.p.pager).slideUp("fast");
					}
					if ($t.p.toppager) {
						$($t.p.toppager).slideUp("fast");
					}
					if ($t.p.toolbar[0] === true) {
						if ($t.p.toolbar[1] == 'both') {
							$($t.grid.ubDiv).slideUp("fast");
						}
						$($t.grid.uDiv).slideUp("fast");
					}
					if ($t.p.footerrow) {
						$(".ui-jqgrid-sdiv", "#gbox_" + $t.p.id).slideUp("fast");
					}
					$(".ui-jqgrid-titlebar-close span", $t.grid.cDiv).removeClass("ui-icon-circle-triangle-n").addClass("ui-icon-circle-triangle-s");
					$t.p.gridstate = 'hidden';
				} else if (state == 'visible') {
					$(".ui-jqgrid-hdiv, .ui-jqgrid-bdiv", "#gview_" + $t.p.id).slideDown("fast");
					if ($t.p.pager) {
						$($t.p.pager).slideDown("fast");
					}
					if ($t.p.toppager) {
						$($t.p.toppager).slideDown("fast");
					}
					if ($t.p.toolbar[0] === true) {
						if ($t.p.toolbar[1] == 'both') {
							$($t.grid.ubDiv).slideDown("fast");
						}
						$($t.grid.uDiv).slideDown("fast");
					}
					if ($t.p.footerrow) {
						$(".ui-jqgrid-sdiv", "#gbox_" + $t.p.id).slideDown("fast");
					}
					$(".ui-jqgrid-titlebar-close span", $t.grid.cDiv).removeClass("ui-icon-circle-triangle-s").addClass("ui-icon-circle-triangle-n");
					$t.p.gridstate = 'visible';
				}
			});
		},
		updateGridRows : function (data, rowidname, jsonreader) {
			var nm,
			success = false,
			title;
			this.each(function () {
				var t = this,
				vl,
				ind,
				srow,
				sid;
				if (!t.grid) {
					return false;
				}
				if (!rowidname) {
					rowidname = "id";
				}
				if (data && data.length > 0) {
					$(data).each(function (j) {
						srow = this;
						ind = t.rows.namedItem(srow[rowidname]);
						if (ind) {
							sid = srow[rowidname];
							if (jsonreader === true) {
								if (t.p.jsonReader.repeatitems === true) {
									if (t.p.jsonReader.cell) {
										srow = srow[t.p.jsonReader.cell];
									}
									for (var k = 0; k < srow.length; k++) {
										vl = t.formatter(sid, srow[k], k, srow, 'edit');
										title = t.p.colModel[k].title ? {
											"title" : $.jgrid.stripHtml(vl)
										}
										 : {};
										if (t.p.treeGrid === true && nm == t.p.ExpandColumn) {
											$("td:eq(" + k + ") > span:first", ind).html(vl).attr(title);
										} else {
											$("td:eq(" + k + ")", ind).html(vl).attr(title);
										}
									}
									success = true;
									return true;
								}
							}
							$(t.p.colModel).each(function (i) {
								nm = jsonreader === true ? this.jsonmap || this.name : this.name;
								if (srow[nm] !== undefined) {
									vl = t.formatter(sid, srow[nm], i, srow, 'edit');
									title = this.title ? {
										"title" : $.jgrid.stripHtml(vl)
									}
									 : {};
									if (t.p.treeGrid === true && nm == t.p.ExpandColumn) {
										$("td:eq(" + i + ") > span:first", ind).html(vl).attr(title);
									} else {
										$("td:eq(" + i + ")", ind).html(vl).attr(title);
									}
									success = true;
								}
							});
						}
					});
				}
			});
			return success;
		},
		filterGrid : function (gridid, p) {
			p = $.extend({
					gridModel : false,
					gridNames : false,
					gridToolbar : false,
					filterModel : [],
					formtype : "horizontal",
					autosearch : true,
					formclass : "filterform",
					tableclass : "filtertable",
					buttonclass : "filterbutton",
					searchButton : "Search",
					clearButton : "Clear",
					enableSearch : false,
					enableClear : false,
					beforeSearch : null,
					afterSearch : null,
					beforeClear : null,
					afterClear : null,
					url : '',
					marksearched : true
				}, p || {});
			return this.each(function () {
				var self = this;
				this.p = p;
				if (this.p.filterModel.length === 0 && this.p.gridModel === false) {
					alert("No filter is set");
					return;
				}
				if (!gridid) {
					alert("No target grid is set!");
					return;
				}
				this.p.gridid = gridid.indexOf("#") != -1 ? gridid : "#" + gridid;
				var gcolMod = $(this.p.gridid).jqGrid("getGridParam", 'colModel');
				if (gcolMod) {
					if (this.p.gridModel === true) {
						var thegrid = $(this.p.gridid)[0];
						var sh;
						$.each(gcolMod, function (i, n) {
							var tmpFil = [];
							this.search = this.search === false ? false : true;
							if (this.editrules && this.editrules.searchhidden === true) {
								sh = true;
							} else {
								if (this.hidden === true) {
									sh = false;
								} else {
									sh = true;
								}
							}
							if (this.search === true && sh === true) {
								if (self.p.gridNames === true) {
									tmpFil.label = thegrid.p.colNames[i];
								} else {
									tmpFil.label = '';
								}
								tmpFil.name = this.name;
								tmpFil.index = this.index || this.name;
								tmpFil.stype = this.edittype || 'text';
								if (tmpFil.stype != 'select') {
									tmpFil.stype = 'text';
								}
								tmpFil.defval = this.defval || '';
								tmpFil.surl = this.surl || '';
								tmpFil.sopt = this.editoptions || {};
								tmpFil.width = this.width;
								self.p.filterModel.push(tmpFil);
							}
						});
					} else {
						$.each(self.p.filterModel, function (i, n) {
							for (var j = 0; j < gcolMod.length; j++) {
								if (this.name == gcolMod[j].name) {
									this.index = gcolMod[j].index || this.name;
									break;
								}
							}
							if (!this.index) {
								this.index = this.name;
							}
						});
					}
				} else {
					alert("Could not get grid colModel");
					return;
				}
				var triggerSearch = function () {
					var sdata = {},
					j = 0,
					v;
					var gr = $(self.p.gridid)[0],
					nm;
					gr.p.searchdata = {};
					if ($.isFunction(self.p.beforeSearch)) {
						self.p.beforeSearch();
					}
					$.each(self.p.filterModel, function (i, n) {
						nm = this.index;
						switch (this.stype) {
						case 'select':
							v = $("select[name=" + nm + "]", self).val();
							if (v) {
								sdata[nm] = v;
								if (self.p.marksearched) {
									$("#jqgh_" + this.name, gr.grid.hDiv).addClass("dirty-cell");
								}
								j++;
							} else {
								if (self.p.marksearched) {
									$("#jqgh_" + this.name, gr.grid.hDiv).removeClass("dirty-cell");
								}
								try {
									delete gr.p.postData[this.index];
								} catch (e) {}
								
							}
							break;
						default:
							v = $("input[name=" + nm + "]", self).val();
							if (v) {
								sdata[nm] = v;
								if (self.p.marksearched) {
									$("#jqgh_" + this.name, gr.grid.hDiv).addClass("dirty-cell");
								}
								j++;
							} else {
								if (self.p.marksearched) {
									$("#jqgh_" + this.name, gr.grid.hDiv).removeClass("dirty-cell");
								}
								try {
									delete gr.p.postData[this.index];
								} catch (e) {}
								
							}
						}
					});
					var sd = j > 0 ? true : false;
					$.extend(gr.p.postData, sdata);
					var saveurl;
					if (self.p.url) {
						saveurl = $(gr).jqGrid("getGridParam", 'url');
						$(gr).jqGrid("setGridParam", {
							url : self.p.url
						});
					}
					$(gr).jqGrid("setGridParam", {
						search : sd
					}).trigger("reloadGrid", [{
								page : 1
							}
						]);
					if (saveurl) {
						$(gr).jqGrid("setGridParam", {
							url : saveurl
						});
					}
					if ($.isFunction(self.p.afterSearch)) {
						self.p.afterSearch();
					}
				};
				var clearSearch = function () {
					var sdata = {},
					v,
					j = 0;
					var gr = $(self.p.gridid)[0],
					nm;
					if ($.isFunction(self.p.beforeClear)) {
						self.p.beforeClear();
					}
					$.each(self.p.filterModel, function (i, n) {
						nm = this.index;
						v = (this.defval) ? this.defval : "";
						if (!this.stype) {
							this.stype = 'text';
						}
						switch (this.stype) {
						case 'select':
							var v1;
							$("select[name=" + nm + "] option", self).each(function (i) {
								if (i === 0) {
									this.selected = true;
								}
								if ($(this).text() == v) {
									this.selected = true;
									v1 = $(this).val();
									return false;
								}
							});
							if (v1) {
								sdata[nm] = v1;
								if (self.p.marksearched) {
									$("#jqgh_" + this.name, gr.grid.hDiv).addClass("dirty-cell");
								}
								j++;
							} else {
								if (self.p.marksearched) {
									$("#jqgh_" + this.name, gr.grid.hDiv).removeClass("dirty-cell");
								}
								try {
									delete gr.p.postData[this.index];
								} catch (e) {}
								
							}
							break;
						case 'text':
							$("input[name=" + nm + "]", self).val(v);
							if (v) {
								sdata[nm] = v;
								if (self.p.marksearched) {
									$("#jqgh_" + this.name, gr.grid.hDiv).addClass("dirty-cell");
								}
								j++;
							} else {
								if (self.p.marksearched) {
									$("#jqgh_" + this.name, gr.grid.hDiv).removeClass("dirty-cell");
								}
								try {
									delete gr.p.postData[this.index];
								} catch (e) {}
								
							}
							break;
						}
					});
					var sd = j > 0 ? true : false;
					$.extend(gr.p.postData, sdata);
					var saveurl;
					if (self.p.url) {
						saveurl = $(gr).jqGrid("getGridParam", 'url');
						$(gr).jqGrid("setGridParam", {
							url : self.p.url
						});
					}
					$(gr).jqGrid("setGridParam", {
						search : sd
					}).trigger("reloadGrid", [{
								page : 1
							}
						]);
					if (saveurl) {
						$(gr).jqGrid("setGridParam", {
							url : saveurl
						});
					}
					if ($.isFunction(self.p.afterClear)) {
						self.p.afterClear();
					}
				};
				var tbl;
				var formFill = function () {
					var tr = document.createElement("tr");
					var tr1,
					sb,
					cb,
					tl,
					td;
					if (self.p.formtype == 'horizontal') {
						$(tbl).append(tr);
					}
					$.each(self.p.filterModel, function (i, n) {
						tl = document.createElement("td");
						$(tl).append("<label for='" + this.name + "'>" + this.label + "</label>");
						td = document.createElement("td");
						var $t = this;
						if (!this.stype) {
							this.stype = 'text';
						}
						switch (this.stype) {
						case "select":
							if (this.surl) {
								$(td).load(this.surl, function () {
									if ($t.defval) {
										$("select", this).val($t.defval);
									}
									$("select", this).attr({
										name : $t.index || $t.name,
										id : "sg_" + $t.name
									});
									if ($t.sopt) {
										$("select", this).attr($t.sopt);
									}
									if (self.p.gridToolbar === true && $t.width) {
										$("select", this).width($t.width);
									}
									if (self.p.autosearch === true) {
										$("select", this).change(function (e) {
											triggerSearch();
											return false;
										});
									}
								});
							} else {
								if ($t.sopt.value) {
									var oSv = $t.sopt.value;
									var elem = document.createElement("select");
									$(elem).attr({
										name : $t.index || $t.name,
										id : "sg_" + $t.name
									}).attr($t.sopt);
									var so,
									sv,
									ov;
									if (typeof oSv === "string") {
										so = oSv.split(";");
										for (var k = 0; k < so.length; k++) {
											sv = so[k].split(":");
											ov = document.createElement("option");
											ov.value = sv[0];
											ov.innerHTML = sv[1];
											if (sv[1] == $t.defval) {
												ov.selected = "selected";
											}
											elem.appendChild(ov);
										}
									} else if (typeof oSv === "object") {
										for (var key in oSv) {
											if (oSv.hasOwnProperty(key)) {
												i++;
												ov = document.createElement("option");
												ov.value = key;
												ov.innerHTML = oSv[key];
												if (oSv[key] == $t.defval) {
													ov.selected = "selected";
												}
												elem.appendChild(ov);
											}
										}
									}
									if (self.p.gridToolbar === true && $t.width) {
										$(elem).width($t.width);
									}
									$(td).append(elem);
									if (self.p.autosearch === true) {
										$(elem).change(function (e) {
											triggerSearch();
											return false;
										});
									}
								}
							}
							break;
						case 'text':
							var df = this.defval ? this.defval : "";
							$(td).append("<input type='text' name='" + (this.index || this.name) + "' id='sg_" + this.name + "' value='" + df + "'/>");
							if ($t.sopt) {
								$("input", td).attr($t.sopt);
							}
							if (self.p.gridToolbar === true && $t.width) {
								if ($.browser.msie) {
									$("input", td).width($t.width - 4);
								} else {
									$("input", td).width($t.width - 2);
								}
							}
							if (self.p.autosearch === true) {
								$("input", td).keypress(function (e) {
									var key = e.charCode ? e.charCode : e.keyCode ? e.keyCode : 0;
									if (key == 13) {
										triggerSearch();
										return false;
									}
									return this;
								});
							}
							break;
						}
						if (self.p.formtype == 'horizontal') {
							if (self.p.gridToolbar === true && self.p.gridNames === false) {
								$(tr).append(td);
							} else {
								$(tr).append(tl).append(td);
							}
							$(tr).append(td);
						} else {
							tr1 = document.createElement("tr");
							$(tr1).append(tl).append(td);
							$(tbl).append(tr1);
						}
					});
					td = document.createElement("td");
					if (self.p.enableSearch === true) {
						sb = "<input type='button' id='sButton' class='" + self.p.buttonclass + "' value='" + self.p.searchButton + "'/>";
						$(td).append(sb);
						$("input#sButton", td).click(function () {
							triggerSearch();
							return false;
						});
					}
					if (self.p.enableClear === true) {
						cb = "<input type='button' id='cButton' class='" + self.p.buttonclass + "' value='" + self.p.clearButton + "'/>";
						$(td).append(cb);
						$("input#cButton", td).click(function () {
							clearSearch();
							return false;
						});
					}
					if (self.p.enableClear === true || self.p.enableSearch === true) {
						if (self.p.formtype == 'horizontal') {
							$(tr).append(td);
						} else {
							tr1 = document.createElement("tr");
							$(tr1).append("<td>&#160;</td>").append(td);
							$(tbl).append(tr1);
						}
					}
				};
				var frm = $("<form name='SearchForm' style=display:inline;' class='" + this.p.formclass + "'></form>");
				tbl = $("<table class='" + this.p.tableclass + "' cellspacing='0' cellpading='0' border='0'><tbody></tbody></table>");
				$(frm).append(tbl);
				formFill();
				$(this).append(frm);
				this.triggerSearch = triggerSearch;
				this.clearSearch = clearSearch;
			});
		},
		filterToolbar : function (p) {
			p = $.extend({
					autosearch : true,
					searchOnEnter : true,
					beforeSearch : null,
					afterSearch : null,
					beforeClear : null,
					afterClear : null,
					searchurl : '',
					stringResult : false,
					groupOp : 'AND',
					defaultSearch : "bw"
				}, p || {});
			return this.each(function () {
				var $t = this;
				var triggerToolbar = function () {
					var sdata = {},
					j = 0,
					v,
					nm,
					sopt = {},
					so;
					$.each($t.p.colModel, function (i, n) {
						nm = this.index || this.name;
						switch (this.stype) {
						case 'select':
							so = (this.searchoptions && this.searchoptions.sopt) ? this.searchoptions.sopt[0] : 'eq';
							v = $("select[name=" + nm + "]", $t.grid.hDiv).val();
							if (v) {
								sdata[nm] = v;
								sopt[nm] = so;
								j++;
							} else {
								try {
									delete $t.p.postData[nm];
								} catch (e) {}
								
							}
							break;
						case 'text':
							so = (this.searchoptions && this.searchoptions.sopt) ? this.searchoptions.sopt[0] : p.defaultSearch;
							v = $("input[name=" + nm + "]", $t.grid.hDiv).val();
							if (v) {
								sdata[nm] = v;
								sopt[nm] = so;
								j++;
							} else {
								try {
									delete $t.p.postData[nm];
								} catch (e) {}
								
							}
							break;
						}
					});
					var sd = j > 0 ? true : false;
					if (p.stringResult === true || $t.p.datatype == "local") {
						var ruleGroup = "{\"groupOp\":\"" + p.groupOp + "\",\"rules\":[";
						var gi = 0;
						$.each(sdata, function (i, n) {
							if (gi > 0) {
								ruleGroup += ",";
							}
							ruleGroup += "{\"field\":\"" + i + "\",";
							ruleGroup += "\"op\":\"" + sopt[i] + "\",";
							ruleGroup += "\"data\":\"" + n + "\"}";
							gi++;
						});
						ruleGroup += "]}";
						$.extend($t.p.postData, {
							filters : ruleGroup
						});
					} else {
						$.extend($t.p.postData, sdata);
					}
					var saveurl;
					if ($t.p.searchurl) {
						saveurl = $t.p.url;
						$($t).jqGrid("setGridParam", {
							url : $t.p.searchurl
						});
					}
					var bsr = false;
					if ($.isFunction(p.beforeSearch)) {
						bsr = p.beforeSearch.call($t);
					}
					if (!bsr) {
						$($t).jqGrid("setGridParam", {
							search : sd
						}).trigger("reloadGrid", [{
									page : 1
								}
							]);
					}
					if (saveurl) {
						$($t).jqGrid("setGridParam", {
							url : saveurl
						});
					}
					if ($.isFunction(p.afterSearch)) {
						p.afterSearch();
					}
				};
				var clearToolbar = function (trigger) {
					var sdata = {},
					v,
					j = 0,
					nm;
					trigger = (typeof trigger != 'boolean') ? true : trigger;
					$.each($t.p.colModel, function (i, n) {
						v = (this.searchoptions && this.searchoptions.defaultValue) ? this.searchoptions.defaultValue : "";
						nm = this.index || this.name;
						switch (this.stype) {
						case 'select':
							var v1;
							$("select[name=" + nm + "] option", $t.grid.hDiv).each(function (i) {
								if (i === 0) {
									this.selected = true;
								}
								if ($(this).text() == v) {
									this.selected = true;
									v1 = $(this).val();
									return false;
								}
							});
							if (v1) {
								sdata[nm] = v1;
								j++;
							} else {
								try {
									delete $t.p.postData[nm];
								} catch (e) {}
								
							}
							break;
						case 'text':
							$("input[name=" + nm + "]", $t.grid.hDiv).val(v);
							if (v) {
								sdata[nm] = v;
								j++;
							} else {
								try {
									delete $t.p.postData[nm];
								} catch (e) {}
								
							}
							break;
						}
					});
					var sd = j > 0 ? true : false;
					if (p.stringResult === true || $t.p.datatype == "local") {
						var ruleGroup = "{\"groupOp\":\"" + p.groupOp + "\",\"rules\":[";
						var gi = 0;
						$.each(sdata, function (i, n) {
							if (gi > 0) {
								ruleGroup += ",";
							}
							ruleGroup += "{\"field\":\"" + i + "\",";
							ruleGroup += "\"op\":\"" + "eq" + "\",";
							ruleGroup += "\"data\":\"" + n + "\"}";
							gi++;
						});
						ruleGroup += "]}";
						$.extend($t.p.postData, {
							filters : ruleGroup
						});
					} else {
						$.extend($t.p.postData, sdata);
					}
					var saveurl;
					if ($t.p.searchurl) {
						saveurl = $t.p.url;
						$($t).jqGrid("setGridParam", {
							url : $t.p.searchurl
						});
					}
					var bcv = false;
					if ($.isFunction(p.beforeClear)) {
						bcv = p.beforeClear.call($t);
					}
					if (!bcv) {
						if (trigger) {
							$($t).jqGrid("setGridParam", {
								search : sd
							}).trigger("reloadGrid", [{
										page : 1
									}
								]);
						}
					}
					if (saveurl) {
						$($t).jqGrid("setGridParam", {
							url : saveurl
						});
					}
					if ($.isFunction(p.afterClear)) {
						p.afterClear();
					}
				};
				var toggleToolbar = function () {
					var trow = $("tr.ui-search-toolbar", $t.grid.hDiv);
					if (trow.css("display") == 'none') {
						trow.show();
					} else {
						trow.hide();
					}
				};
				function bindEvents(selector, events) {
					var jElem = $(selector);
					if (jElem[0]) {
						jQuery.each(events, function () {
							if (this.data !== undefined) {
								jElem.bind(this.type, this.data, this.fn);
							} else {
								jElem.bind(this.type, this.fn);
							}
						});
					}
				}
				var tr = $("<tr class='ui-search-toolbar' role='rowheader'></tr>");
				var timeoutHnd;
				$.each($t.p.colModel, function (i, n) {
					var cm = this,
					thd,
					th,
					soptions,
					surl,
					self;
					th = $("<th role='columnheader' class='ui-state-default ui-th-column ui-th-" + $t.p.direction + "'></th>");
					thd = $("<div style='width:100%;position:relative;height:100%;padding-right:0.3em;'></div>");
					if (this.hidden === true) {
						$(th).css("display", "none");
					}
					this.search = this.search === false ? false : true;
					if (typeof this.stype == 'undefined') {
						this.stype = 'text';
					}
					soptions = $.extend({}, this.searchoptions || {});
					if (this.search) {
						switch (this.stype) {
						case "select":
							surl = this.surl || soptions.dataUrl;
							if (surl) {
								self = thd;
								$.ajax($.extend({
										url : surl,
										dataType : "html",
										complete : function (res, status) {
											if (soptions.buildSelect !== undefined) {
												var d = soptions.buildSelect(res);
												if (d) {
													$(self).append(d);
												}
											} else {
												$(self).append(res.responseText);
											}
											if (soptions.defaultValue) {
												$("select", self).val(soptions.defaultValue);
											}
											$("select", self).attr({
												name : cm.index || cm.name,
												id : "gs_" + cm.name
											});
											if (soptions.attr) {
												$("select", self).attr(soptions.attr);
											}
											$("select", self).css({
												width : "100%"
											});
											if (soptions.dataInit !== undefined) {
												soptions.dataInit($("select", self)[0]);
											}
											if (soptions.dataEvents !== undefined) {
												bindEvents($("select", self)[0], soptions.dataEvents);
											}
											if (p.autosearch === true) {
												$("select", self).change(function (e) {
													triggerToolbar();
													return false;
												});
											}
											res = null;
										}
									}, $.jgrid.ajaxOptions, $t.p.ajaxSelectOptions || {}));
							} else {
								var oSv;
								if (cm.searchoptions && cm.searchoptions.value) {
									oSv = cm.searchoptions.value;
								} else if (cm.editoptions && cm.editoptions.value) {
									oSv = cm.editoptions.value;
								}
								if (oSv) {
									var elem = document.createElement("select");
									elem.style.width = "100%";
									$(elem).attr({
										name : cm.index || cm.name,
										id : "gs_" + cm.name
									});
									var so,
									sv,
									ov;
									if (typeof oSv === "string") {
										so = oSv.split(";");
										for (var k = 0; k < so.length; k++) {
											sv = so[k].split(":");
											ov = document.createElement("option");
											ov.value = sv[0];
											ov.innerHTML = sv[1];
											elem.appendChild(ov);
										}
									} else if (typeof oSv === "object") {
										for (var key in oSv) {
											if (oSv.hasOwnProperty(key)) {
												ov = document.createElement("option");
												ov.value = key;
												ov.innerHTML = oSv[key];
												elem.appendChild(ov);
											}
										}
									}
									if (soptions.defaultValue) {
										$(elem).val(soptions.defaultValue);
									}
									if (soptions.attr) {
										$(elem).attr(soptions.attr);
									}
									if (soptions.dataInit !== undefined) {
										soptions.dataInit(elem);
									}
									if (soptions.dataEvents !== undefined) {
										bindEvents(elem, soptions.dataEvents);
									}
									$(thd).append(elem);
									if (p.autosearch === true) {
										$(elem).change(function (e) {
											triggerToolbar();
											return false;
										});
									}
								}
							}
							break;
						case 'text':
							var df = soptions.defaultValue ? soptions.defaultValue : "";
							$(thd).append("<input type='text' style='width:95%;padding:0px;' name='" + (cm.index || cm.name) + "' id='gs_" + cm.name + "' value='" + df + "'/>");
							if (soptions.attr) {
								$("input", thd).attr(soptions.attr);
							}
							if (soptions.dataInit !== undefined) {
								soptions.dataInit($("input", thd)[0]);
							}
							if (soptions.dataEvents !== undefined) {
								bindEvents($("input", thd)[0], soptions.dataEvents);
							}
							if (p.autosearch === true) {
								if (p.searchOnEnter) {
									$("input", thd).keypress(function (e) {
										var key = e.charCode ? e.charCode : e.keyCode ? e.keyCode : 0;
										if (key == 13) {
											triggerToolbar();
											return false;
										}
										return this;
									});
								} else {
									$("input", thd).keydown(function (e) {
										var key = e.which;
										switch (key) {
										case 13:
											return false;
										case 9:
										case 16:
										case 37:
										case 38:
										case 39:
										case 40:
										case 27:
											break;
										default:
											if (timeoutHnd) {
												clearTimeout(timeoutHnd);
											}
											timeoutHnd = setTimeout(function () {
													triggerToolbar();
												}, 500);
										}
									});
								}
							}
							break;
						}
					}
					$(th).append(thd);
					$(tr).append(th);
				});
				$("table thead", $t.grid.hDiv).append(tr);
				this.triggerToolbar = triggerToolbar;
				this.clearToolbar = clearToolbar;
				this.toggleToolbar = toggleToolbar;
			});
		}
	});
})(jQuery); ;
(function ($) {
	if ($.browser.msie && $.browser.version == 8) {
		$.expr[":"].hidden = function (elem) {
			return elem.offsetWidth === 0 || elem.offsetHeight === 0 || elem.style.display == "none";
		};
	}
	$.jgrid._multiselect = false;
	if ($.ui) {
		if ($.ui.multiselect) {
			if ($.ui.multiselect.prototype._setSelected) {
				var setSelected = $.ui.multiselect.prototype._setSelected;
				$.ui.multiselect.prototype._setSelected = function (item, selected) {
					var ret = setSelected.call(this, item, selected);
					if (selected && this.selectedList) {
						var elt = this.element;
						this.selectedList.find('li').each(function () {
							if ($(this).data('optionLink')) {
								$(this).data('optionLink').remove().appendTo(elt);
							}
						});
					}
					return ret;
				};
			}
			if ($.ui.multiselect.prototype.destroy) {
				$.ui.multiselect.prototype.destroy = function () {
					this.element.show();
					this.container.remove();
					if ($.Widget === undefined) {
						$.widget.prototype.destroy.apply(this, arguments);
					} else {
						$.Widget.prototype.destroy.apply(this, arguments);
					}
				};
			}
			$.jgrid._multiselect = true;
		}
	}
	$.jgrid.extend({
		sortableColumns : function (tblrow) {
			return this.each(function () {
				var ts = this;
				function start() {
					ts.p.disableClick = true;
				}
				var sortable_opts = {
					"tolerance" : "pointer",
					"axis" : "x",
					"scrollSensitivity" : "1",
					"items" : '>th:not(:has(#jqgh_cb,#jqgh_rn,#jqgh_subgrid),:hidden)',
					"placeholder" : {
						element : function (item) {
							var el = $(document.createElement(item[0].nodeName)).addClass(item[0].className + " ui-sortable-placeholder ui-state-highlight").removeClass("ui-sortable-helper")[0];
							return el;
						},
						update : function (self, p) {
							p.height(self.currentItem.innerHeight() - parseInt(self.currentItem.css('paddingTop') || 0, 10) - parseInt(self.currentItem.css('paddingBottom') || 0, 10));
							p.width(self.currentItem.innerWidth() - parseInt(self.currentItem.css('paddingLeft') || 0, 10) - parseInt(self.currentItem.css('paddingRight') || 0, 10));
						}
					},
					"update" : function (event, ui) {
						var p = $(ui.item).parent();
						var th = $(">th", p);
						var colModel = ts.p.colModel;
						var cmMap = {};
						$.each(colModel, function (i) {
							cmMap[this.name] = i;
						});
						var permutation = [];
						th.each(function (i) {
							var id = $(">div", this).get(0).id.replace(/^jqgh_/, "");
							if (id in cmMap) {
								permutation.push(cmMap[id]);
							}
						});
						$(ts).jqGrid("remapColumns", permutation, true, true);
						if ($.isFunction(ts.p.sortable.update)) {
							ts.p.sortable.update(permutation);
						}
						setTimeout(function () {
							ts.p.disableClick = false;
						}, 50);
					}
				};
				if (ts.p.sortable.options) {
					$.extend(sortable_opts, ts.p.sortable.options);
				} else if ($.isFunction(ts.p.sortable)) {
					ts.p.sortable = {
						"update" : ts.p.sortable
					};
				}
				if (sortable_opts.start) {
					var s = sortable_opts.start;
					sortable_opts.start = function (e, ui) {
						start();
						s.call(this, e, ui);
					};
				} else {
					sortable_opts.start = start;
				}
				if (ts.p.sortable.exclude) {
					sortable_opts.items += ":not(" + ts.p.sortable.exclude + ")";
				}
				tblrow.sortable(sortable_opts).data("sortable").floating = true;
			});
		},
		columnChooser : function (opts) {
			var self = this;
			if ($("#colchooser_" + self[0].p.id).length) {
				return;
			}
			var selector = $('<div id="colchooser_' + self[0].p.id + '" style="position:relative;overflow:hidden"><div><select multiple="multiple"></select></div></div>');
			var select = $('select', selector);
			function insert(perm, i, v) {
				if (i >= 0) {
					var a = perm.slice();
					var b = a.splice(i, Math.max(perm.length - i, i));
					if (i > perm.length) {
						i = perm.length;
					}
					a[i] = v;
					return a.concat(b);
				}
			}
			opts = $.extend({
					"width" : 420,
					"height" : 240,
					"classname" : null,
					"done" : function (perm) {
						if (perm) {
							self.jqGrid("remapColumns", perm, true);
						}
					},
					"msel" : "multiselect",
					"dlog" : "dialog",
					"dlog_opts" : function (opts) {
						var buttons = {};
						buttons[opts.bSubmit] = function () {
							opts.apply_perm();
							opts.cleanup(false);
						};
						buttons[opts.bCancel] = function () {
							opts.cleanup(true);
						};
						return {
							"buttons" : buttons,
							"close" : function () {
								opts.cleanup(true);
							},
							"modal" : false,
							"resizable" : false,
							"width" : opts.width + 20
						};
					},
					"apply_perm" : function () {
						$('option', select).each(function (i) {
							if (this.selected) {
								self.jqGrid("showCol", colModel[this.value].name);
							} else {
								self.jqGrid("hideCol", colModel[this.value].name);
							}
						});
						var perm = [];
						$('option[selected]', select).each(function () {
							perm.push(parseInt(this.value, 10));
						});
						$.each(perm, function () {
							delete colMap[colModel[parseInt(this, 10)].name];
						});
						$.each(colMap, function () {
							var ti = parseInt(this, 10);
							perm = insert(perm, ti, ti);
						});
						if (opts.done) {
							opts.done.call(self, perm);
						}
					},
					"cleanup" : function (calldone) {
						call(opts.dlog, selector, 'destroy');
						call(opts.msel, select, 'destroy');
						selector.remove();
						if (calldone && opts.done) {
							opts.done.call(self);
						}
					},
					"msel_opts" : {}
					
				}, $.jgrid.col, opts || {});
			if ($.ui) {
				if ($.ui.multiselect) {
					if (opts.msel == "multiselect") {
						if (!$.jgrid._multiselect) {
							alert("Multiselect plugin loaded after jqGrid. Please load the plugin before the jqGrid!");
							return;
						}
						opts.msel_opts = $.extend($.ui.multiselect.defaults, opts.msel_opts);
					}
				}
			}
			if (opts.caption) {
				selector.attr("title", opts.caption);
			}
			if (opts.classname) {
				selector.addClass(opts.classname);
				select.addClass(opts.classname);
			}
			if (opts.width) {
				$(">div", selector).css({
					"width" : opts.width,
					"margin" : "0 auto"
				});
				select.css("width", opts.width);
			}
			if (opts.height) {
				$(">div", selector).css("height", opts.height);
				select.css("height", opts.height - 10);
			}
			var colModel = self.jqGrid("getGridParam", "colModel");
			var colNames = self.jqGrid("getGridParam", "colNames");
			var colMap = {},
			fixedCols = [];
			select.empty();
			$.each(colModel, function (i) {
				colMap[this.name] = i;
				if (this.hidedlg) {
					if (!this.hidden) {
						fixedCols.push(i);
					}
					return;
				}
				select.append("<option value='" + i + "' " +
					(this.hidden ? "" : "selected='selected'") + ">" + colNames[i] + "</option>");
			});
			function call(fn, obj) {
				if (!fn) {
					return;
				}
				if (typeof fn == 'string') {
					if ($.fn[fn]) {
						$.fn[fn].apply(obj, $.makeArray(arguments).slice(2));
					}
				} else if ($.isFunction(fn)) {
					fn.apply(obj, $.makeArray(arguments).slice(2));
				}
			}
			var dopts = $.isFunction(opts.dlog_opts) ? opts.dlog_opts.call(self, opts) : opts.dlog_opts;
			call(opts.dlog, selector, dopts);
			var mopts = $.isFunction(opts.msel_opts) ? opts.msel_opts.call(self, opts) : opts.msel_opts;
			call(opts.msel, select, mopts);
		},
		sortableRows : function (opts) {
			return this.each(function () {
				var $t = this;
				if (!$t.grid) {
					return;
				}
				if ($t.p.treeGrid) {
					return;
				}
				if ($.fn.sortable) {
					opts = $.extend({
							"cursor" : "move",
							"axis" : "y",
							"items" : ".jqgrow"
						}, opts || {});
					if (opts.start && $.isFunction(opts.start)) {
						opts._start_ = opts.start;
						delete opts.start;
					} else {
						opts._start_ = false;
					}
					if (opts.update && $.isFunction(opts.update)) {
						opts._update_ = opts.update;
						delete opts.update;
					} else {
						opts._update_ = false;
					}
					opts.start = function (ev, ui) {
						$(ui.item).css("border-width", "0px");
						$("td", ui.item).each(function (i) {
							this.style.width = $t.grid.cols[i].style.width;
						});
						if ($t.p.subGrid) {
							var subgid = $(ui.item).attr("id");
							try {
								$($t).jqGrid('collapseSubGridRow', subgid);
							} catch (e) {}
							
						}
						if (opts._start_) {
							opts._start_.apply(this, [ev, ui]);
						}
					};
					opts.update = function (ev, ui) {
						$(ui.item).css("border-width", "");
						if ($t.p.rownumbers === true) {
							$("td.jqgrid-rownum", $t.rows).each(function (i) {
								$(this).html(i + 1);
							});
						}
						if (opts._update_) {
							opts._update_.apply(this, [ev, ui]);
						}
					};
					$("tbody:first", $t).sortable(opts);
					$("tbody:first", $t).disableSelection();
				}
			});
		},
		gridDnD : function (opts) {
			return this.each(function () {
				var $t = this;
				if (!$t.grid) {
					return;
				}
				if ($t.p.treeGrid) {
					return;
				}
				if (!$.fn.draggable || !$.fn.droppable) {
					return;
				}
				function updateDnD() {
					var datadnd = $.data($t, "dnd");
					$("tr.jqgrow:not(.ui-draggable)", $t).draggable($.isFunction(datadnd.drag) ? datadnd.drag.call($($t), datadnd) : datadnd.drag);
				}
				var appender = "<table id='jqgrid_dnd' class='ui-jqgrid-dnd'></table>";
				if ($("#jqgrid_dnd").html() === null) {
					$('body').append(appender);
				}
				if (typeof opts == 'string' && opts == 'updateDnD' && $t.p.jqgdnd === true) {
					updateDnD();
					return;
				}
				opts = $.extend({
						"drag" : function (opts) {
							return $.extend({
								start : function (ev, ui) {
									if ($t.p.subGrid) {
										var subgid = $(ui.helper).attr("id");
										try {
											$($t).jqGrid('collapseSubGridRow', subgid);
										} catch (e) {}
										
									}
									for (var i = 0; i < $.data($t, "dnd").connectWith.length; i++) {
										if ($($.data($t, "dnd").connectWith[i]).jqGrid('getGridParam', 'reccount') == "0") {
											$($.data($t, "dnd").connectWith[i]).jqGrid('addRowData', 'jqg_empty_row', {});
										}
									}
									ui.helper.addClass("ui-state-highlight");
									$("td", ui.helper).each(function (i) {
										this.style.width = $t.grid.headers[i].width + "px";
									});
									if (opts.onstart && $.isFunction(opts.onstart)) {
										opts.onstart.call($($t), ev, ui);
									}
								},
								stop : function (ev, ui) {
									if (ui.helper.dropped) {
										var ids = $(ui.helper).attr("id");
										$($t).jqGrid('delRowData', ids);
									}
									for (var i = 0; i < $.data($t, "dnd").connectWith.length; i++) {
										$($.data($t, "dnd").connectWith[i]).jqGrid('delRowData', 'jqg_empty_row');
									}
									if (opts.onstop && $.isFunction(opts.onstop)) {
										opts.onstop.call($($t), ev, ui);
									}
								}
							}, opts.drag_opts || {});
						},
						"drop" : function (opts) {
							return $.extend({
								accept : function (d) {
									var tid = $(d).closest("table.ui-jqgrid-btable");
									if ($.data(tid[0], "dnd") !== undefined) {
										var cn = $.data(tid[0], "dnd").connectWith;
										return $.inArray('#' + this.id, cn) != -1 ? true : false;
									}
									return d;
								},
								drop : function (ev, ui) {
									var accept = $(ui.draggable).attr("id");
									var getdata = ui.draggable.parent().parent().jqGrid('getRowData', accept);
									if (!opts.dropbyname) {
										var j = 0,
										tmpdata = {},
										dropname;
										var dropmodel = $("#" + this.id).jqGrid('getGridParam', 'colModel');
										try {
											for (var key in getdata) {
												if (getdata.hasOwnProperty(key) && dropmodel[j]) {
													dropname = dropmodel[j].name;
													tmpdata[dropname] = getdata[key];
												}
												j++;
											}
											getdata = tmpdata;
										} catch (e) {}
										
									}
									ui.helper.dropped = true;
									if (opts.beforedrop && $.isFunction(opts.beforedrop)) {
										var datatoinsert = opts.beforedrop.call(this, ev, ui, getdata, $('#' + $t.id), $(this));
										if (typeof datatoinsert != "undefined" && datatoinsert !== null && typeof datatoinsert == "object") {
											getdata = datatoinsert;
										}
									}
									if (ui.helper.dropped) {
										var grid;
										if (opts.autoid) {
											if ($.isFunction(opts.autoid)) {
												grid = opts.autoid.call(this, getdata);
											} else {
												grid = Math.ceil(Math.random() * 1000);
												grid = opts.autoidprefix + grid;
											}
										}
										$("#" + this.id).jqGrid('addRowData', grid, getdata, opts.droppos);
									}
									if (opts.ondrop && $.isFunction(opts.ondrop)) {
										opts.ondrop.call(this, ev, ui, getdata);
									}
								}
							}, opts.drop_opts || {});
						},
						"onstart" : null,
						"onstop" : null,
						"beforedrop" : null,
						"ondrop" : null,
						"drop_opts" : {
							"activeClass" : "ui-state-active",
							"hoverClass" : "ui-state-hover"
						},
						"drag_opts" : {
							"revert" : "invalid",
							"helper" : "clone",
							"cursor" : "move",
							"appendTo" : "#jqgrid_dnd",
							"zIndex" : 5000
						},
						"dropbyname" : false,
						"droppos" : "first",
						"autoid" : true,
						"autoidprefix" : "dnd_"
					}, opts || {});
				if (!opts.connectWith) {
					return;
				}
				opts.connectWith = opts.connectWith.split(",");
				opts.connectWith = $.map(opts.connectWith, function (n) {
						return $.trim(n);
					});
				$.data($t, "dnd", opts);
				if ($t.p.reccount != "0" && !$t.p.jqgdnd) {
					updateDnD();
				}
				$t.p.jqgdnd = true;
				for (var i = 0; i < opts.connectWith.length; i++) {
					var cn = opts.connectWith[i];
					$(cn).droppable($.isFunction(opts.drop) ? opts.drop.call($($t), opts) : opts.drop);
				}
			});
		},
		gridResize : function (opts) {
			return this.each(function () {
				var $t = this;
				if (!$t.grid || !$.fn.resizable) {
					return;
				}
				opts = $.extend({}, opts || {});
				if (opts.alsoResize) {
					opts._alsoResize_ = opts.alsoResize;
					delete opts.alsoResize;
				} else {
					opts._alsoResize_ = false;
				}
				if (opts.stop && $.isFunction(opts.stop)) {
					opts._stop_ = opts.stop;
					delete opts.stop;
				} else {
					opts._stop_ = false;
				}
				opts.stop = function (ev, ui) {
					$($t).jqGrid('setGridParam', {
						height : $("#gview_" + $t.p.id + " .ui-jqgrid-bdiv").height()
					});
					$($t).jqGrid('setGridWidth', ui.size.width, opts.shrinkToFit);
					if (opts._stop_) {
						opts._stop_.call($t, ev, ui);
					}
				};
				if (opts._alsoResize_) {
					var optstest = "{\'#gview_" + $t.p.id + " .ui-jqgrid-bdiv\':true,'" + opts._alsoResize_ + "':true}";
					opts.alsoResize = eval('(' + optstest + ')');
				} else {
					opts.alsoResize = $(".ui-jqgrid-bdiv", "#gview_" + $t.p.id);
				}
				delete opts._alsoResize_;
				$("#gbox_" + $t.p.id).resizable(opts);
			});
		}
	});
})(jQuery); ;
(function ($) {
	$.jgrid.extend({
		setSubGrid : function () {
			return this.each(function () {
				var $t = this,
				cm;
				$t.p.colNames.unshift("");
				$t.p.colModel.unshift({
					name : 'subgrid',
					width : $.browser.safari ? $t.p.subGridWidth : $t.p.subGridWidth,
					sortable : false,
					resizable : false,
					hidedlg : true,
					search : false,
					fixed : true
				});
				cm = $t.p.subGridModel;
				if (cm[0]) {
					cm[0].align = $.extend([], cm[0].align || []);
					for (var i = 0; i < cm[0].name.length; i++) {
						cm[0].align[i] = cm[0].align[i] || 'left';
					}
				}
			});
		},
		addSubGridCell : function (pos, iRow) {
			var prp = '',
			gv,
			sid;
			this.each(function () {
				prp = this.formatCol(pos, iRow);
				gv = this.p.gridview;
				sid = this.p.id;
			});
			if (gv === false) {
				return "<td role=\"grid\" aria-describedby=\"" + sid + "_subgrid\" class=\"ui-sgcollapsed sgcollapsed\" " + prp + "><a href='javascript:void(0);'><span class='ui-icon ui-icon-plus'></span></a></td>";
			} else {
				return "<td role=\"grid\" aria-describedby=\"" + sid + "_subgrid\" " + prp + "></td>";
			}
		},
		addSubGrid : function (t, pos) {
			return this.each(function () {
				var ts = this;
				if (!ts.grid) {
					return;
				}
				var subGridCell = function (trdiv, cell, pos) {
					var tddiv = $("<td align='" + ts.p.subGridModel[0].align[pos] + "'></td>").html(cell);
					$(trdiv).append(tddiv);
				};
				var subGridXml = function (sjxml, sbid) {
					var tddiv,
					i,
					sgmap,
					dummy = $("<table cellspacing='0' cellpadding='0' border='0'><tbody></tbody></table>"),
					trdiv = $("<tr></tr>");
					for (i = 0; i < ts.p.subGridModel[0].name.length; i++) {
						tddiv = $("<th class='ui-state-default ui-th-subgrid ui-th-column ui-th-" + ts.p.direction + "'></th>");
						$(tddiv).html(ts.p.subGridModel[0].name[i]);
						$(tddiv).width(ts.p.subGridModel[0].width[i]);
						$(trdiv).append(tddiv);
					}
					$(dummy).append(trdiv);
					if (sjxml) {
						sgmap = ts.p.xmlReader.subgrid;
						$(sgmap.root + " " + sgmap.row, sjxml).each(function () {
							trdiv = $("<tr class='ui-widget-content ui-subtblcell'></tr>");
							if (sgmap.repeatitems === true) {
								$(sgmap.cell, this).each(function (i) {
									subGridCell(trdiv, $(this).text() || '&#160;', i);
								});
							} else {
								var f = ts.p.subGridModel[0].mapping || ts.p.subGridModel[0].name;
								if (f) {
									for (i = 0; i < f.length; i++) {
										subGridCell(trdiv, $(f[i], this).text() || '&#160;', i);
									}
								}
							}
							$(dummy).append(trdiv);
						});
					}
					var pID = $("table:first", ts.grid.bDiv).attr("id") + "_";
					$("#" + pID + sbid).append(dummy);
					ts.grid.hDiv.loading = false;
					$("#load_" + ts.p.id).hide();
					return false;
				};
				var subGridJson = function (sjxml, sbid) {
					var tddiv,
					result,
					i,
					cur,
					sgmap,
					j,
					dummy = $("<table cellspacing='0' cellpadding='0' border='0'><tbody></tbody></table>"),
					trdiv = $("<tr></tr>");
					for (i = 0; i < ts.p.subGridModel[0].name.length; i++) {
						tddiv = $("<th class='ui-state-default ui-th-subgrid ui-th-column ui-th-" + ts.p.direction + "'></th>");
						$(tddiv).html(ts.p.subGridModel[0].name[i]);
						$(tddiv).width(ts.p.subGridModel[0].width[i]);
						$(trdiv).append(tddiv);
					}
					$(dummy).append(trdiv);
					if (sjxml) {
						sgmap = ts.p.jsonReader.subgrid;
						result = sjxml[sgmap.root];
						if (typeof result !== 'undefined') {
							for (i = 0; i < result.length; i++) {
								cur = result[i];
								trdiv = $("<tr class='ui-widget-content ui-subtblcell'></tr>");
								if (sgmap.repeatitems === true) {
									if (sgmap.cell) {
										cur = cur[sgmap.cell];
									}
									for (j = 0; j < cur.length; j++) {
										subGridCell(trdiv, cur[j] || '&#160;', j);
									}
								} else {
									var f = ts.p.subGridModel[0].mapping || ts.p.subGridModel[0].name;
									if (f.length) {
										for (j = 0; j < f.length; j++) {
											subGridCell(trdiv, cur[f[j]] || '&#160;', j);
										}
									}
								}
								$(dummy).append(trdiv);
							}
						}
					}
					var pID = $("table:first", ts.grid.bDiv).attr("id") + "_";
					$("#" + pID + sbid).append(dummy);
					ts.grid.hDiv.loading = false;
					$("#load_" + ts.p.id).hide();
					return false;
				};
				var populatesubgrid = function (rd) {
					var sid,
					dp,
					i,
					j;
					sid = $(rd).attr("id");
					dp = {
						nd_ : (new Date().getTime())
					};
					dp[ts.p.prmNames.subgridid] = sid;
					if (!ts.p.subGridModel[0]) {
						return false;
					}
					if (ts.p.subGridModel[0].params) {
						for (j = 0; j < ts.p.subGridModel[0].params.length; j++) {
							for (i = 0; i < ts.p.colModel.length; i++) {
								if (ts.p.colModel[i].name == ts.p.subGridModel[0].params[j]) {
									dp[ts.p.colModel[i].name] = $("td:eq(" + i + ")", rd).text().replace(/\&#160\;/ig, '');
								}
							}
						}
					}
					if (!ts.grid.hDiv.loading) {
						ts.grid.hDiv.loading = true;
						$("#load_" + ts.p.id).show();
						if (!ts.p.subgridtype) {
							ts.p.subgridtype = ts.p.datatype;
						}
						if ($.isFunction(ts.p.subgridtype)) {
							ts.p.subgridtype.call(ts, dp);
						} else {
							ts.p.subgridtype = ts.p.subgridtype.toLowerCase();
						}
						switch (ts.p.subgridtype) {
						case "xml":
						case "json":
							$.ajax($.extend({
									type : ts.p.mtype,
									url : ts.p.subGridUrl,
									dataType : ts.p.subgridtype,
									data : $.isFunction(ts.p.serializeSubGridData) ? ts.p.serializeSubGridData(ts, dp) : dp,
									complete : function (sxml) {
										if (ts.p.subgridtype == "xml") {
											subGridXml(sxml.responseXML, sid);
										} else {
											subGridJson($.jgrid.parse(sxml.responseText), sid);
										}
										sxml = null;
									}
								}, $.jgrid.ajaxOptions, ts.p.ajaxSubgridOptions || {}));
							break;
						}
					}
					return false;
				};
				var res,
				_id,
				pID,
				atd,
				nhc,
				subdata,
				bfsc;
				$("td:eq(" + pos + ")", t).click(function (e) {
					if ($(this).hasClass("sgcollapsed")) {
						pID = ts.p.id;
						res = $(this).parent();
						atd = pos >= 1 ? "<td colspan='" + pos + "'>&#160;</td>" : "";
						_id = $(res).attr("id");
						bfsc = true;
						if ($.isFunction(ts.p.subGridBeforeExpand)) {
							bfsc = ts.p.subGridBeforeExpand.call(ts, pID + "_" + _id, _id);
						}
						if (bfsc === false) {
							return false;
						}
						nhc = 0;
						$.each(ts.p.colModel, function (i, v) {
							if (this.hidden === true || this.name == 'rn' || this.name == 'cb') {
								nhc++;
							}
						});
						subdata = "<tr role='row' class='ui-subgrid'>" + atd + "<td class='ui-widget-content subgrid-cell'style='border-top: 1px solid #C4D5DF;'><span class='ui-icon ui-icon-carat-1-sw'/></td><td colspan='" + parseInt(ts.p.colNames.length - 1 - nhc, 10) + "' class='ui-widget-content subgrid-data'><div id=" + pID + "_" + _id + " class='tablediv'>";
						$(this).parent().after(subdata + "</div></td></tr>");
						if ($.isFunction(ts.p.subGridRowExpanded)) {
							ts.p.subGridRowExpanded.call(ts, pID + "_" + _id, _id);
						} else {
							populatesubgrid(res);
						}
						$(this).html("<a href='javascript:void(0);'><span class='ui-icon ui-icon-minus'></span></a>").removeClass("sgcollapsed").addClass("sgexpanded");
					} else if ($(this).hasClass("sgexpanded")) {
						bfsc = true;
						if ($.isFunction(ts.p.subGridRowColapsed)) {
							res = $(this).parent();
							_id = $(res).attr("id");
							bfsc = ts.p.subGridRowColapsed.call(ts, pID + "_" + _id, _id);
						}
						if (bfsc === false) {
							return false;
						}
						$(this).parent().next().remove(".ui-subgrid");
						$(this).html("<a href='javascript:void(0);'><span class='ui-icon ui-icon-plus'></span></a>").removeClass("sgexpanded").addClass("sgcollapsed");
					}
					return false;
				});
				ts.subGridXml = function (xml, sid) {
					subGridXml(xml, sid);
				};
				ts.subGridJson = function (json, sid) {
					subGridJson(json, sid);
				};
			});
		},
		expandSubGridRow : function (rowid) {
			return this.each(function () {
				var $t = this;
				if (!$t.grid && !rowid) {
					return;
				}
				if ($t.p.subGrid === true) {
					var rc = $(this).jqGrid("getInd", rowid, true);
					if (rc) {
						var sgc = $("td.sgcollapsed", rc)[0];
						if (sgc) {
							$(sgc).trigger("click");
						}
					}
				}
			});
		},
		collapseSubGridRow : function (rowid) {
			return this.each(function () {
				var $t = this;
				if (!$t.grid && !rowid) {
					return;
				}
				if ($t.p.subGrid === true) {
					var rc = $(this).jqGrid("getInd", rowid, true);
					if (rc) {
						var sgc = $("td.sgexpanded", rc)[0];
						if (sgc) {
							$(sgc).trigger("click");
						}
					}
				}
			});
		},
		toggleSubGridRow : function (rowid) {
			return this.each(function () {
				var $t = this;
				if (!$t.grid && !rowid) {
					return;
				}
				if ($t.p.subGrid === true) {
					var rc = $(this).jqGrid("getInd", rowid, true);
					if (rc) {
						var sgc = $("td.sgcollapsed", rc)[0];
						if (sgc) {
							$(sgc).trigger("click");
						} else {
							sgc = $("td.sgexpanded", rc)[0];
							if (sgc) {
								$(sgc).trigger("click");
							}
						}
					}
				}
			});
		}
	});
})(jQuery); ;
(function ($) {
	var ua = navigator.userAgent;
	var moz = $.browser.mozilla && /gecko/i.test(ua);
	var webkit = $.browser.safari && /Safari\/[5-9]/.test(ua);
	var expr = $.browser.msie && (function () {
			var div = document.createElement('div');
			try {
				div.style.setExpression('width', '0+0');
				div.style.removeExpression('width');
			} catch (e) {
				return false;
			}
			return true;
		})();
	function sz(el, p) {
		return parseInt($.css(el, p)) || 0;
	};
	function hex2(s) {
		var s = parseInt(s).toString(16);
		return (s.length < 2) ? '0' + s : s;
	};
	function gpc(node) {
		for (; node && node.nodeName.toLowerCase() != 'html'; node = node.parentNode) {
			var v = $.css(node, 'backgroundColor');
			if (v == 'rgba(0, 0, 0, 0)')
				continue;
			if (v.indexOf('rgb') >= 0) {
				var rgb = v.match(/\d+/g);
				return '#' + hex2(rgb[0]) + hex2(rgb[1]) + hex2(rgb[2]);
			}
			if (v && v != 'transparent')
				return v;
		}
		return '#ffffff';
	};
	function getWidth(fx, i, width) {
		switch (fx) {
		case 'round':
			return Math.round(width * (1 - Math.cos(Math.asin(i / width))));
		case 'cool':
			return Math.round(width * (1 + Math.cos(Math.asin(i / width))));
		case 'sharp':
			return Math.round(width * (1 - Math.cos(Math.acos(i / width))));
		case 'bite':
			return Math.round(width * (Math.cos(Math.asin((width - i - 1) / width))));
		case 'slide':
			return Math.round(width * (Math.atan2(i, width / i)));
		case 'jut':
			return Math.round(width * (Math.atan2(width, (width - i - 1))));
		case 'curl':
			return Math.round(width * (Math.atan(i)));
		case 'tear':
			return Math.round(width * (Math.cos(i)));
		case 'wicked':
			return Math.round(width * (Math.tan(i)));
		case 'long':
			return Math.round(width * (Math.sqrt(i)));
		case 'sculpt':
			return Math.round(width * (Math.log((width - i - 1), width)));
		case 'dog':
			return (i & 1) ? (i + 1) : width;
		case 'dog2':
			return (i & 2) ? (i + 1) : width;
		case 'dog3':
			return (i & 3) ? (i + 1) : width;
		case 'fray':
			return (i % 2) * width;
		case 'notch':
			return width;
		case 'bevel':
			return i + 1;
		}
	};
	$.fn.corner = function (options) {
		if (this.length == 0) {
			if (!$.isReady && this.selector) {
				var s = this.selector,
				c = this.context;
				$(function () {
					$(s, c).corner(options);
				});
			}
			return this;
		}
		return this.each(function (index) {
			var $this = $(this);
			var o = [options || '', $this.attr($.fn.corner.defaults.metaAttr) || ''].join(' ').toLowerCase();
			var keep = /keep/.test(o);
			var cc = ((o.match(/cc:(#[0-9a-f]+)/) || [])[1]);
			var sc = ((o.match(/sc:(#[0-9a-f]+)/) || [])[1]);
			var width = parseInt((o.match(/(\d+)px/) || [])[1]) || 10;
			var re = /round|bevel|notch|bite|cool|sharp|slide|jut|curl|tear|fray|wicked|sculpt|long|dog3|dog2|dog/;
			var fx = ((o.match(re) || ['round'])[0]);
			var edges = {
				T : 0,
				B : 1
			};
			var opts = {
				TL : /top|tl|left/.test(o),
				TR : /top|tr|right/.test(o),
				BL : /bottom|bl|left/.test(o),
				BR : /bottom|br|right/.test(o)
			};
			if (!opts.TL && !opts.TR && !opts.BL && !opts.BR)
				opts = {
					TL : 1,
					TR : 1,
					BL : 1,
					BR : 1
				};
			if ($.fn.corner.defaults.useNative && fx == 'round' && (moz || webkit) && !cc && !sc) {
				if (opts.TL)
					$this.css(moz ? '-moz-border-radius-topleft' : '-webkit-border-top-left-radius', width + 'px');
				if (opts.TR)
					$this.css(moz ? '-moz-border-radius-topright' : '-webkit-border-top-right-radius', width + 'px');
				if (opts.BL)
					$this.css(moz ? '-moz-border-radius-bottomleft' : '-webkit-border-bottom-left-radius', width + 'px');
				if (opts.BR)
					$this.css(moz ? '-moz-border-radius-bottomright' : '-webkit-border-bottom-right-radius', width + 'px');
				return;
			}
			var strip = document.createElement('div');
			strip.style.overflow = 'hidden';
			strip.style.height = '1px';
			strip.style.backgroundColor = sc || 'transparent';
			strip.style.borderStyle = 'solid';
			var pad = {
				T : parseInt($.css(this, 'paddingTop')) || 0,
				R : parseInt($.css(this, 'paddingRight')) || 0,
				B : parseInt($.css(this, 'paddingBottom')) || 0,
				L : parseInt($.css(this, 'paddingLeft')) || 0
			};
			if (typeof this.style.zoom != undefined)
				this.style.zoom = 1;
			if (!keep)
				this.style.border = 'none';
			strip.style.borderColor = cc || gpc(this.parentNode);
			var cssHeight = $.curCSS(this, 'height');
			for (var j in edges) {
				var bot = edges[j];
				if ((bot && (opts.BL || opts.BR)) || (!bot && (opts.TL || opts.TR))) {
					strip.style.borderStyle = 'none ' + (opts[j + 'R'] ? 'solid' : 'none') + ' none ' + (opts[j + 'L'] ? 'solid' : 'none');
					var d = document.createElement('div');
					$(d).addClass('jquery-corner');
					var ds = d.style;
					bot ? this.appendChild(d) : this.insertBefore(d, this.firstChild);
					if (bot && cssHeight != 'auto') {
						if ($.css(this, 'position') == 'static')
							this.style.position = 'relative';
						ds.position = 'absolute';
						ds.bottom = ds.left = ds.padding = ds.margin = '0';
						if (expr)
							ds.setExpression('width', 'this.parentNode.offsetWidth');
						else
							ds.width = '100%';
					} else if (!bot && $.browser.msie) {
						if ($.css(this, 'position') == 'static')
							this.style.position = 'relative';
						ds.position = 'absolute';
						ds.top = ds.left = ds.right = ds.padding = ds.margin = '0';
						if (expr) {
							var bw = sz(this, 'borderLeftWidth') + sz(this, 'borderRightWidth');
							ds.setExpression('width', 'this.parentNode.offsetWidth - ' + bw + '+ "px"');
						} else
							ds.width = '100%';
					} else {
						ds.position = 'relative';
						ds.margin = !bot ? '-' + pad.T + 'px -' + pad.R + 'px ' + (pad.T - width) + 'px -' + pad.L + 'px' : (pad.B - width) + 'px -' + pad.R + 'px -' + pad.B + 'px -' + pad.L + 'px';
					}
					for (var i = 0; i < width; i++) {
						var w = Math.max(0, getWidth(fx, i, width));
						var e = strip.cloneNode(false);
						e.style.borderWidth = '0 ' + (opts[j + 'R'] ? w : 0) + 'px 0 ' + (opts[j + 'L'] ? w : 0) + 'px';
						bot ? d.appendChild(e) : d.insertBefore(e, d.firstChild);
					}
				}
			}
		});
	};
	$.fn.uncorner = function () {
		if (moz || webkit)
			this.css(moz ? '-moz-border-radius' : '-webkit-border-radius', 0);
		$('div.jquery-corner', this).remove();
		return this;
	};
	$.fn.corner.defaults = {
		useNative : true,
		metaAttr : 'data-corner'
	};
})(jQuery);
